2016-06-24 3 views
-2

Activity xmlのデザインビューでは、リニアレイアウトのボタンが表示されますが、完全に配置されているように見えますが、GenyMotoin avdで見ると、期待される。 さまざまな画面サイズでボタンの位置を動的に調整するにはどうすればよいですか?Android Studioでボタンの位置を動的に調整する

私のxmlファイル:一番外側のレイアウト用

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.xxx.MainScreen" 
    android:background="#b6b6b6"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="263dp" 
      android:id="@+id/textView" 
      android:textSize="50dp" /> 

    </LinearLayout> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="264dp"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Next Act" 
      android:id="@+id/button" 
      android:layout_marginTop="100dp" 
      android:layout_marginLeft="20dp" /> 
    </LinearLayout> 
</RelativeLayout> 
+0

あなたの質問は? – aditya

+0

1.問題を具体的に記述してください。 2. xmlファイルを投稿します。 3.あなたは何を達成したいのですか、今何を得ていますか? – Kunu

+0

あなたは今まで何をしましたか? –

答えて

0

使用リニアレイアウト。

0

あなたが達成しようとしていることは明らかではありませんが、すべてのデバイスの中央にビューを配置したい場合は、 LinearLayoutの代わりにRelativeLayoutを使用してください:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#b6b6b6" 
    android:padding="@dimen/activity_vertical_margin" 
    android:weightSum="2" 
    android:orientation="vertical" 
    tools:context="com.offtogeek.motivatemyself.MainScreen"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_centerInParent="true" 
      android:gravity="left" 
      android:textSize="50dp" /> 

    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_weight="1" 
      android:text="Next Quote" /> 

    </RelativeLayout> 

</LinearLayout> 
関連する問題