Нижняя панель кнопок Android и вид прокрутки с темой диалога - PullRequest
5 голосов
/ 11 марта 2011

Я пытаюсь отобразить активность Android с:

  • тема диалога;
  • заголовок, зафиксированный в верхней части диалогового окна;
  • панель кнопок, закрепленная в нижней части диалога;
  • вид прокрутки в середине.

Макет, который я написал, удовлетворяет этим критериям, за исключением того, что диалоговое окно всегда заполняет весь экран (см. Вертикальный снимок экрана внизу).

Это мой макет:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">

    <TextView android:id="@+id/header"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_marginLeft="10dp" android:layout_marginRight="10dp"
    android:layout_marginTop="10dp" android:layout_marginBottom="10dp"
    android:gravity="center_vertical"
        android:textSize="18dip" android:textColor="#ffffff"
        android:text="Sample Layout" />

    <LinearLayout android:id="@+id/controls" android:orientation="horizontal"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    style="@android:style/ButtonBar">
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_weight="1" android:text="Yes" />
        <Button android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_weight="1" android:text="No" />
    </LinearLayout>

    <ScrollView android:id="@+id/test" android:layout_below="@id/header"
    android:layout_above="@id/controls"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_marginBottom="5dp" android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp">
        <TextView android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:text="Lorem ipsum dolor sit amet, consectetur
        adipiscing elit. Integer dui odio, convallis vitae suscipit eu,
        tincidunt non mi. Vestibulum faucibus pretium purus vel adipiscing.
        Morbi mattis molestie risus vitae vehicula. [...]" />
    </ScrollView>

</RelativeLayout>

Кроме того, задание стилизовано с @android:style/Theme.Dialog и android:windowNoTitle.

Я не уверен, что понимаю, почему этот макет расширяется, чтобы заполнить весь экран. Ни в одном из представлений высота макета не установлена ​​на fill_parent; родительский макет также не установлен на fill_parent.

Кто-нибудь знает, возможно ли то, что я хочу сделать, и если да, то как это сделать?

Мой текущий макет в горизонтальном режиме

Layout in horizontal mode.

Мой текущий макет в вертикальном режиме

Layout in vertical mode.

Ответы [ 2 ]

11 голосов
/ 15 марта 2011

У меня есть активность, которая очень похожа на вашу. Я сделал это некоторое время назад, поэтому я не помню, почему я сделал это и то, но я думаю, что достигну того, что вы пытаетесь сделать. Вот мой код:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/info_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="bottom"
android:background="@color/color2">

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/color1">

    <TextView
        android:id="@+id/infos_titre"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="12dip"
        android:textSize="20dip"
        android:textColor="@color/color2"
        android:gravity="center"
        android:background="@color/color1">
    </TextView>

</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/infos_LL"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center_vertical">

            <TextView
                android:id="@+id/infos_text"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="16dip"
                android:padding="4dip"
                android:textColor="@color/color1"
                android:lineSpacingMultiplier="1.1"
                android:autoLink="web">
            </TextView>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/color1"
    android:paddingTop="6dip">

    <Button
        android:id="@+id/infos_remarquebutton"
        android:text="Faire une remarque"
        android:drawableLeft="@drawable/happy"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:textColor="@color/buttontext_color">
    </Button>
    <Button
        android:id="@+id/infos_partagerbutton"
        android:text="Partager"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/ic_menu_share"
        android:layout_weight="1"
        android:textColor="@color/buttontext_color">
    </Button>
</LinearLayout>

Не беспокойтесь из-за названий Frenglish ...

Итак, я думаю, что основной хитростью было поместить ScrollView внутри в LinearLayout. Я также дал вес 1 этой LinearLayout (я не помню, почему ...). Кроме того, верхний макет - это LinearLayout, а не относительный макет, как в вашем коде, но я не думаю, что это что-то изменит, хотя я не знаком с RelativeLayouts.

Надеюсь, это поможет!

0 голосов
/ 11 марта 2011

Я думаю, что так как вы указали android: layout_alignParentBottom = "true" для линейного макета, кнопка перемещается вниз, и это выглядит следующим образом ..

Так что лучше удалить android: layout_alignParentBottom = "true" и использовать android: layout_marginTop = "некоторые значения"

Попробуйте, пожалуйста .. Спасибо ..

...