Android - 使用剩余空间的动态滚动视图大小

时间:2014-05-24 21:04:03

标签: android scrollview

已编辑以改进细节:

嗨,我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:padding="10dp"
tools:context="${packageName}.${activityClass}" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_weight="1"
    android:text="Select Character"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#ffffff" />

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_below="@+id/textView1"
    android:orientation="vertical"
    android:paddingTop="10dp" >

    <TextView
        android:id="@+id/SelectedCharacterName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#ffffff" />

    <TextView
        android:id="@+id/TraitName1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Trait 1"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#ffffff" />

        etc...

</LinearLayout>

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="0"
    android:fillViewport="false"
    android:paddingTop="10dp" >

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

        <TextView
            android:id="@+id/Character1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#4a4a4a"
            android:clickable="true"
            android:gravity="center"
            android:text="Character 1"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#ffffff" />

            etc...

    </LinearLayout>
</ScrollView>

<Button
    android:id="@+id/buttonConfirmCharacter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_gravity="center"
    android:text="@string/button_Confirm" />

</LinearLayout>

我希望使scrollview适合其他元素之间的剩余空间,但是使用此设置,scrollview似乎根本不呈现。这些设置是寻找解决方案和实施重量的结果。

没有java代码的答案是优惠的。

感谢。

1 个答案:

答案 0 :(得分:0)

在这里,这样可以正常使用

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Text1" />

   <TextView
        android:id="@+id/SelectedCharacterName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name"
        android:layout_marginTop="10dp" />

   <TextView
        android:id="@+id/TraitName1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Trait 1" />

        etc...

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true"
        android:paddingTop="10dp" >

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

            <TextView
                android:id="@+id/Character1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:gravity="center"
                android:text="Character 1" />

                etc...
        </LinearLayout>
    </ScrollView>

    <Button
        android:id="@+id/buttonConfirmCharacter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="@string/button_Confirm" /></LinearLayout>
相关问题