【问题标题】:The TextView is not shown and the ScrollView is not scrolling未显示 TextView 且 ScrollView 未滚动
【发布时间】:2013-09-08 14:11:51
【问题描述】:

我想要一个 ScrollView 上方的粘性 TextView:

文本视图应覆盖屏幕的 50%,因此我将文本视图和内部线性布局的权重设置为“1”。

但是 TextView 根本没有显示,而且 ScrollView 没有滚动!

任何帮助将不胜感激!

<RelativeLayout 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:background="#000000"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/wallbg"
        android:gravity="bottom"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:height="0dp"
            android:text="Some Text!"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@android:color/white"
            android:textSize="50sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/wallbg"
            android:gravity="bottom"
            android:orientation="vertical" >

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true" >

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

                    <Button
                        android:id="@+id/btn1"
                        android:layout_width="200dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_margin="10dp"
                        android:background="@drawable/btnbg"
                        android:text="Some Text!"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/font_size" />

                    <Button
                        android:id="@+id/btn4"
                        android:layout_width="200dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_margin="10dp"
                        android:background="@drawable/btnbg"
                        android:text="Some Text!"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/font_size" />

                    <Button
                        android:id="@+id/btn2"
                        android:layout_width="200dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_margin="10dp"
                        android:background="@drawable/btnbg"
                        android:text="Some Text!"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/font_size" />

                    <Button
                        android:id="@+id/btn3"
                        android:layout_width="200dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_margin="10dp"
                        android:background="@drawable/btnbg"
                        android:text="Some Text!"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/font_size" />
                </LinearLayout>
            </ScrollView>
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

【问题讨论】:

    标签: android xml scrollview


    【解决方案1】:

    看起来您根本不需要RelativeLayout。只需将您的外部LinearLayout 设置为根视图并将其layout_height 属性设置为match_parent(这是主要问题)。此外,ScrollView 内的LinearLayout 应该有wrap_content 的layout_height。

    【讨论】:

      猜你喜欢
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多