LinearLayouts: один фиксированный и один с переменной высотой - PullRequest
0 голосов
/ 01 апреля 2019

Я хотел бы добавить верхнюю полосу с двумя кнопками в вертикальной линейной линейке с высотой ровно 100 dp.

Так что я хотел бы видеть верхнюю часть в 100 dp и переменную верхнюю панель под ней.

Я пытаюсь этот код, но он не работает.Я вижу, что он не принимает 100 dp в качестве допустимого значения, но я не знаю, как добиться того, что я хотел бы сделать с LinearLayout.

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

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

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button 1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button 2" />
    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </View>
</LinearLayout>

Ответы [ 2 ]

1 голос
/ 01 апреля 2019

Вы добавили пробел между 100 и dp (100 dp), удалите пробел и скомпилируйте свой код.

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

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

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button 1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Button 2" />
    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </View>
</LinearLayout>
1 голос
/ 01 апреля 2019

Попробуйте после удаления пробела в 100dp

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

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

        <Button
                android:id="@+id/button1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="Button 1" />

        <Button
                android:id="@+id/button2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="Button 2" />
    </LinearLayout>
    <View
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    </View>
</LinearLayout> 
...