2016-12-14 4 views
0

Ich verwende 2 innere Linearlayouts, um meinen Bildschirm in 2 Abschnitte zu teilen. Es sieht wie folgt aus:2 Ansichten nebeneinander mit der gleichen Höhe

Screenshot

Der erste innere Aufbau hat eine Textview und ein Button. Der zweite hat eine ImageView und auch einen Button. Jetzt möchte ich die gleiche Höhe für TextView und ImageView erreichen, ohne einen festen Wert für layout_height zu setzen. Die linke Taste sollte ebenfalls mit der rechten Taste übereinstimmen.

Hier ist meine xml:

<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:orientation="horizontal" 
      tools:context="de.dk.masterfi.ActMain"> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_margin="20dp" 
    android:layout_weight="1" 
    android:orientation="vertical"> 


    <TextView 
     android:id="@+id/text" 
     android:layout_width="wrap_content" 
     android:layout_height="280dp" 
     android:background="@drawable/border" 
     android:padding="10dp" 
     android:text="@string/welcome"/> 

    <Button android:id="@+id/button2" android:layout_width="match_parent" 
      android:layout_height="wrap_content" android:text="Favoriten"/> 


</LinearLayout> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_margin="20dp" 
    android:layout_weight="1" 
    android:orientation="vertical"> 

    <ImageView 
     android:id="@+id/imageView" 
     android:layout_width="wrap_content" 
     android:layout_height="280dp" android:src="@drawable/training"/> 

    <Button android:layout_width="match_parent" android:layout_height="wrap_content" 
      android:text="Hauptmenü"/> 

</LinearLayout> 

Antwort

1

dies versuchen, notieren Sie die android:layout_weight="1" Attribut für TextView und ImageView:

<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:orientation="horizontal" 
     tools:context="de.dk.masterfi.ActMain"> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_margin="20dp" 
     android:layout_weight="1" 
     android:orientation="vertical"> 
     <TextView 
      android:id="@+id/text" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="@drawable/border" 
      android:padding="10dp" 
      android:text="@string/welcome"/> 
     <Button 
      android:id="@+id/button2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Favoriten"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_margin="20dp" 
     android:layout_weight="1" 
     android:orientation="vertical"> 
     <ImageView 
      android:id="@+id/imageView" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:src="@drawable/training"/> 
     <Button 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Hauptmenü"/> 
    </LinearLayout> 
</LinearLayout> 
+0

Wow, danke! Sehr gute Lösung. –

0

Versuchen this:

android:layout_height = "0dp" 
android:layout_weight = "1.0" 

ändern das Gewicht nach Ihren Angaben

0

ändern xml

<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:orientation="horizontal" 
     tools:context="de.dk.masterfi.ActMain"> 

<LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_margin="20dp" 
     android:layout_weight="1" 
     android:orientation="vertical"> 


     <TextView 
      android:id="@+id/text" 
      android:layout_width="wrap_content" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:background="@drawable/border" 
      android:padding="10dp" 
      android:text="@string/welcome"/> 

     <Button android:id="@+id/button2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Favoriten"/> 

</LinearLayout> 
<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_margin="20dp" 
    android:layout_weight="1" 
    android:orientation="vertical"> 

<ImageView 
    android:id="@+id/imageView" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:src="@drawable/training" 
    android:layout_weight="1"/> 

    <Button android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Hauptmenü"/> 

</LinearLayout> 

</LinearLayout> 
0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_trail" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:orientation="horizontal" 
    tools:context="com.nividbharat.educompanion.activities.TrailActivity"> 
    <RelativeLayout 
     android:id="@+id/relLayout1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="16dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginTop="16dp" 
     android:layout_weight="0.5" 
     android:background="@android:color/black" 
     android:orientation="vertical"> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/button1" 
      android:background="@android:color/holo_red_dark" /> 
     <Button 
      android:id="@+id/button1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:text="Button1" /> 
    </RelativeLayout> 
    <RelativeLayout 
     android:id="@+id/relLayout2" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="16dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     android:layout_weight="0.5" 
     android:background="@android:color/black"> 
     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@+id/button2" 
      android:background="@android:color/holo_red_dark" /> 
     <Button 
      android:id="@+id/button2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:text="Button2" /> 
    </RelativeLayout> 
</LinearLayout> 

Dies ist, wie die Vorschau des Layouts aussehen,

enter image description here

Verwandte Themen