【问题标题】:LinearLayout inside ScrollView not visibleScrollView 内的 LinearLayout 不可见
【发布时间】:2015-03-27 12:40:01
【问题描述】:

当将 RelativeLayout 放入 ScrollView 时,我在将片段附加到 RelativeLayout 时遇到问题。亲爱的请看xml代码——

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

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="48dp" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:textColor="#9982d6"
            android:textSize="20sp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginTop="10dp"
            android:gravity="center_vertical"
            android:textColor="#9982d6"
            android:textSize="20sp"/>
    </RelativeLayout>

    <View
        android:id="@+id/topDivider2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#9982d6"
        />

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textColor="#848484"
            android:textSize="14sp" />

        <View
            android:layout_width="match_parent"
            android:layout_height="3.5dp"
            android:layout_alignParentBottom="true"
            android:background="#4ccdd9"
            android:visibility="gone" />

        <View
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="4dp"
            android:layout_marginTop="4dp" />
    </RelativeLayout>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:dividerHeight="0dp" />

</LinearLayout>

</ScrollView>

在上面的 xml 代码中,我必须在 RelativeLayout GraphContainer 中附加一个片段,该片段不起作用。如果我不使用 ScrollView,则附加片段有效。请帮忙...

【问题讨论】:

  • 将线性布局高度改为fill_parent
  • 为什么要将第一个RelativeLayout高度提供给match_parent,在垂直方向的线性布局内。
  • 滚动视图高度应始终为 wrap_content 否则意义较小
  • 建议使用布局权重
  • 更改 ScrollView、LinearLayout 和 RelativeLayout 的高度都不起作用。

标签: android android-layout android-fragments android-relativelayout xml-layout


【解决方案1】:

android:fillViewport 属性添加到滚动视图。它会工作的!

作为

  <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:obs="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:fillViewport="true" >

//===== furter code

【讨论】:

  • 我试过了,但它显示错误-在包'android'中找不到属性'fillViewPort'的资源标识符
  • 使用这个 android:fillViewport="true" 使端口的“P”变小
  • poor 适合 android:fillViewport="true" 和 android:layout_height=”match_parent” 对于滚动视图意味着“将高度设置为父级的高度”。这显然不是您在使用 ScrollView 时想要的。毕竟,如果 ScrollView 的内容总是和它自己一样高,它就会变得毫无用处。
  • android:fillViewport="true" 在我的情况下不起作用。
【解决方案2】:

如果您希望您的片段可滚动而不是从此 xml 中删除 ScrollView 并将其放入片段的 xml 中。另外我可以看到你在 ScrollView 中定义了一个 ListView,它不会以这种方式工作,因为 ListView 有自己的 ScrollView。

【讨论】:

    【解决方案3】:

    尝试在覆盖整个活动的布局中使用滚动视图。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="any_bg_color">
    
    
     <ScrollView 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" >
    
    //other layouts and views here
    
     </ScrollView>
    </RelativeLayout>
    

    【讨论】:

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