【问题标题】:Scrollview in two Linearlayouts?两个线性布局中的滚动视图?
【发布时间】:2017-12-09 15:09:33
【问题描述】:

我的Activity 中有4 个TextViews,我正在使用垂直方向的LinearLayout。前一个TextView 是一种标题(无需滚动),下一个是我想要使其可滚动的某种描述。第三个是标题(不需要滚动),第四个是描述(需要滚动)。 我试过了,但屏幕上只显示了顶部TextView(标题)和第二个TextView(描述)。描述是可滚动的,但问题是,其他两个TextView 被隐藏了。 这是一个愚蠢的问题,但我有点卡在这里,因为我是安卓新手。这是我的xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?android:attr/actionBarSize"
android:orientation="vertical"
android:padding="15dp"

>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#d0f7c9"
    android:orientation="vertical"
    android:padding="10dp"

    >

    <TextView
        android:id="@+id/tvTitle"
        style="?android:attr/listSeparatorTextViewStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="#ffffff"
        android:textSize="20dp" />

</LinearLayout>


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

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#b3cff4"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tvShow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textSize="20dp" />
    </LinearLayout>
</ScrollView>


<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Program Output"
    android:textColor="@color/black"
    android:textSize="25dp" />


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

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#d2b3f4">

        <TextView
            android:id="@+id/tvOutput"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ffffff"
            android:textSize="20dp" />

    </LinearLayout>

</ScrollView>

【问题讨论】:

    标签: android android-linearlayout textview android-scroll


    【解决方案1】:

    你可以这样试试,

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"
                  android:weightSum="2">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#d0f7c9"
            android:orientation="vertical">
    
            <TextView
                android:id="@+id/tvTitle"
                style="?android:attr/listSeparatorTextViewStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Top Title"
                android:textColor="#ffffff"
                android:textSize="20dp"/>
    
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#b3cff4">
    
                <TextView
                    android:id="@+id/tvShow"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:textSize="20dp"/>
            </ScrollView>
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">
    
            <TextView
                android:id="@+id/tvTitle1"
                style="?android:attr/listSeparatorTextViewStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Seconf Title"
                android:textColor="#ffffff"
                android:textSize="20dp"/>
    
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#b3cff4">
    
                <TextView
                    android:id="@+id/tvShow1"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:textSize="20dp"/>
            </ScrollView>
        </LinearLayout>
    
    </LinearLayout>
    

    【讨论】:

    • 你成就了我的一天。谢谢
    【解决方案2】:

    我可能会这样做的方式是创建两个布局。一个是数字 1 和 2 文本视图。另一个布局是 3 和 4。然后在第一个布局中,包括第二个。

    <include layout="@layout/layout2"/>
    

    类似的东西。 布局一个

    <linearlayout>
    <text view>
    <linearlayout>
    <scrollview>
    <textview>
    </scrollview>
    </linearlayout>
    
    <include layout="@layout/layout2"/>
    
    </linearlayout>
    

    布局二

       <linearlayout>
        <text view>
        <linearlayout>
        <scrollview>
        <textview>
        </scrollview>
        </linearlayout>   
        </linear layout>
    

    【讨论】:

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