scrollview с плавающей linearlayout не будет прокручиваться - PullRequest
4 голосов
/ 01 апреля 2011

Вот мой GUI XML:

<FrameLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/frameLayout"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ScrollView android:layout_width="fill_parent" android:id="@+id/scrollView"
        android:fillViewport="true" android:layout_height="fill_parent">

        <LinearLayout android:layout_width="fill_parent"
            android:orientation="vertical" android:id="@+id/contentLayout"
            android:padding="5dip" android:fadingEdge="vertical"
            android:layout_height="fill_parent">
            <TextView android:id="@+id/lblName" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="@string/label_name"></TextView>
            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:id="@+id/nameLayout">
                <CheckBox android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:id="@+id/chkName"></CheckBox>
                <TextView android:layout_marginLeft="4dip"
                    android:layout_marginRight="4dip" android:id="@+id/txtName"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:textColor="@color/white" android:text="TextView"
                    android:layout_weight="1" android:textSize="20dip"></TextView>
            </LinearLayout>
            <TextView android:id="@+id/lblPhone" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="@string/label_phone"></TextView>
            <LinearLayout android:isScrollContainer="false"
                android:layout_width="fill_parent" android:layout_height="wrap_content"
                android:orientation="vertical" android:id="@+id/lstPhone"></LinearLayout>
            <TextView android:id="@+id/lblEmail" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="@string/label_email"></TextView>
            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:orientation="vertical"
                android:id="@+id/lstEmail"></LinearLayout>
            <TextView android:id="@+id/lblAddress" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="@string/label_address"></TextView>
            <LinearLayout android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:orientation="vertical"
                android:id="@+id/lstAddress"></LinearLayout>
        </LinearLayout>
    </ScrollView>
    <LinearLayout android:background="@color/grey"
        android:layout_width="fill_parent" android:paddingTop="5dip"
        android:layout_height="wrap_content" android:orientation="horizontal"
        android:layout_gravity="bottom|right" android:id="@+id/commandLayout">
        <Button android:id="@+id/btnToClipBoard" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:text="To ClipBoard"
            android:layout_weight="1"></Button>
        <Button android:id="@+id/btnCancel" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:text="Cancel"
            android:layout_weight="1"></Button>
    </LinearLayout>
</FrameLayout>

Идентификатор LinearLayout: commandLayout удобно располагается внизу окна. Но идентификатор LinearLayout: contentLayout не будет прокручиваться. Если я перемещаю commandLayout внутри scrollView, все прокручивается. Это не то, что я хочу. Я хочу видеть кнопки независимо от того, как долго работает contentLayout. Любая помощь будет принята с благодарностью. Я провел большую часть дня на этом ... Спасибо.

Редактировать: Спасибо за все ответы. Переход от FrameLayout к RelativeLayout и установка commandLayout align родительского дна и родительского верха выравнивания scrollview были решением, которое работало лучше всего.

Ответы [ 3 ]

1 голос
/ 07 апреля 2011

Я изменил базовый макет, а именно "frameLayout", на относительный макет.

Я делаю это так, чтобы «commandLayout» был ниже «scrollView». Не имеет смысла, если то, что вы собираетесь показать, скрыто за "commandLayout"

Я добавил alignParentBottom в "commandLayout". Я также добавил layout_above = "@ + id / commandLayout" в "scrollView"

это рабочий xml и да, он прокручивается =)

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/relativeLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ScrollView 
    android:layout_width="fill_parent"
    android:id="@+id/scrollView"
    android:fillViewport="true"
    android:layout_height="fill_parent"
    android:layout_above="@+id/commandLayout"
>
    <LinearLayout 
        android:layout_width="fill_parent"
        android:orientation="vertical"
        android:id="@+id/contentLayout"
        android:padding="5dip"
        android:fadingEdge="vertical"
        android:layout_height="fill_parent"
    >
        <TextView
            android:id="@+id/lblName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        >
        </TextView>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/nameLayout"
        >
            <CheckBox 
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/chkName">
            </CheckBox>
            <TextView
                android:layout_marginLeft="4dip"
                android:layout_marginRight="4dip"
                android:id="@+id/txtName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#FFFFFF"
                android:text="TextView"
                android:layout_weight="1"
                android:textSize="20dip">
            </TextView>
        </LinearLayout>

        <TextView
            android:id="@+id/lblPhone"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        >
        </TextView>
        <LinearLayout
            android:isScrollContainer="false"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/lstPhone">
        </LinearLayout>
        <TextView
            android:id="@+id/lblEmail"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        >
        </TextView>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/lstEmail"
        >
        </LinearLayout>
        <TextView
            android:id="@+id/lblAddress"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        >
        </TextView>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:id="@+id/lstAddress">
        </LinearLayout>
        <TextView
            android:id="@+id/LongText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="40sp"
            android:text="This is a super long text that will hopefully cover the whole screen so as the scroll will work."
        >
        </TextView>

         <TextView
            android:id="@+id/AnotherLongText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="40sp"
            android:text="This is another super long text to show that the scrolling will work even more!"
        >
        </TextView>
    </LinearLayout>
</ScrollView>

<LinearLayout
    android:background="#737754"
    android:layout_width="fill_parent"
    android:paddingTop="5dip"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/commandLayout"
    android:layout_alignParentBottom="true"
>
    <Button
        android:id="@+id/btnToClipBoard"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="To ClipBoard"
        android:layout_weight="1">
    </Button>
    <Button
        android:id="@+id/btnCancel"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="Cancel"
        android:layout_weight="1">
    </Button>
</LinearLayout>
</RelativeLayout>
1 голос
/ 05 апреля 2011

Нужно ли использовать FrameLayout? Если я правильно понял вашу цель, возможно, RelativeLayout сделал то, что вы ожидали;

<RelativeLayout ...>
    <LinearLayout
        android:layout_alignParentBottom="true"
        android:id="@+id/commandLayout" ... />
    <ScrollView
        android:layout_alignParentTop="true"
        android:layout_above="@id/commandLayout"
        android:id="@+id/scrollView" .../>
</RelativeLayout>
0 голосов
/ 06 апреля 2011

Я, вероятно, не понял, в чем проблема полностью, но здесь идет ... Я попробовал файл макета, который вы подняли, и обнаружил, что нижняя часть списка скрыта за двумя кнопками. Поэтому я добавил следующее в виджет ScrollView, и это выглядело нормально.

android:layout_marginBottom="60dip"

Но, может быть, я что-то упустил.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...