2017-11-19 5 views
1

Ich muss die Höhe des Layouts auf 50% setzen, aber es gibt nicht android:layout_height="0.5", wie kann ich es einstellen?Set Layout Höhe

<?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:orientation="vertical" 
    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.wt.pr.ResultsActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0.5" 
     android:orientation="horizontal"> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0.5" 
     android:orientation="vertical"> 
    </LinearLayout> 
</LinearLayout> 

Antwort

1

Sie benötigen Attribut als android:layout_weight=0.5 verwenden und stellen Sie Ihre layout_height=0dp wo

oder es kann einfach android:layout_weight=1 für beide

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

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

Versuchen sein unter code.you Gewicht Eigenschaft gesetzt und Höhe einstellen 0dp

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" 
     android:orientation="horizontal"> 
    </LinearLayout> 
0

Eine Option besteht darin, zu der neuen ConstraintLayout zu wechseln. Sie hat Optionen, um die Höhe auf% des Bildschirms zu setzen. Eine weitere Option ist die Verwendung von 'layout_weight'. Da Sie ein LinearLayout als Root-Layout verwenden, können Sie das Gewicht der inneren Layouts festlegen.

<?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:orientation="vertical" 
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.wt.pr.ResultsActivity"> 

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

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