2016-06-24 9 views
-2

Ich habe einen Button im linearen Layout, wenn ich in der Design-Ansicht von Activity XML sehe, sieht es aus wie es perfekt positioniert ist, aber wenn ich in GenyMotoin avd sehe, ist es weit von dem, was ich platziert erwartet. Wie kann die Position der Taste auf verschiedenen Bildschirmgrößen dynamisch angepasst werden?Dynamisch Position von Button in Android Studio anpassen

Meine XML-Datei:

<?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

und Ihre Fragen sind? – aditya

+0

1. Bitte seien Sie speziell auf Ihr Problem. 2. Veröffentlichen Sie Ihre XML-Datei. 3. Was möchten Sie erreichen und was bekommen Sie jetzt? – Kunu

+0

was hast du bis jetzt gemacht? –

Antwort

0

Verwendung Linear-Layout für die äußerste Layout.

0

Es ist nicht klar, was Sie erreichen möchten, aber wenn Sie Ihre Ansichten in der Mitte auf allen Geräten positionieren möchten. Versuchen Sie RelativeLayout statt LinearLayout zu verwenden:

<?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> 
Verwandte Themen