android - ScrollView 不显示

标签 android scrollview

当使用下面显示的布局时,ScrollView 不显示,而如果我在树 (@id/top_bar) 之前删除 RelativeLayout,它会显示。任何人都可以解释为什么?

谢谢

七月

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/item_detail" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout android:id="@+id/top_bar"
        android:layout_width="fill_parent" android:layout_height="44dp"
        android:background="@drawable/nav_bar">
        <ImageButton android:id="@+id/btn_map"
            android:layout_width="34dp" android:layout_height="34dp"
            android:src="@drawable/btn_map"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true"
            android:layout_marginRight="10dp" />
        <TextView android:id="@+id/top_bar_title"
            android:layout_width="200dp" android:layout_height="wrap_content"
            android:layout_centerVertical="true" android:gravity="center"
            android:textSize="16sp" android:textColor="#FFFFFF"
            android:textStyle="bold" android:layout_marginLeft="60dp" />
    </RelativeLayout>

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

        <LinearLayout android:layout_width="fill_parent"
            android:layout_height="200dp">
            <RelativeLayout android:layout_width="fill_parent"
                android:layout_height="200dp">
                <ViewFlipper android:id="@+id/itemdetail_gallery"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                </ViewFlipper>
                <RelativeLayout android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
                    <ImageView android:id="@+id/btn_gallery_prev"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:src="@drawable/bg_diapo_left"
                        android:layout_marginLeft="5dp"
                        android:layout_width="30dp"
                        android:layout_height="50dp" android:visibility="gone" />
                    <ImageView android:id="@+id/btn_gallery_next"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:src="@drawable/bg_diapo_right"
                        android:layout_marginRight="5dp"
                        android:layout_width="30dp"
                        android:layout_height="50dp" android:visibility="gone" />
                    <TextView android:id="@+id/btn_gallery_ind"
                        android:layout_alignParentTop="true"
                        android:layout_alignParentRight="true"
                        android:layout_marginTop="5dp"
                        android:layout_marginRight="5dp"
                        android:background="@drawable/bg_diapo_ind"
                        android:gravity="center" android:layout_width="30dp"
                        android:layout_height="20dp" android:visibility="gone" />
                </RelativeLayout>
            </RelativeLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

最佳答案

LinearLayout 的默认方向是水平的。 ScrollView 被放置在 RelativeLayout 旁边。因为你有 android:layout_width="fill_parent" 你的 ScrollView 永远不会被显示。如果您希望您的布局是垂直的,那么您需要这样设置。尝试在您的 LinearLayout 中设置 android:orientation="vertical"

关于android - ScrollView 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6178780/

相关文章:

java - 在 Android 中处理多个 xml 文件

Android 在可扩展 ListView 中禁用自动滚动

android - 当我将 Webview 放在 android 中的 ScrollView 中时,底部会添加空白

android - 让 scrollview 填满整个屏幕,除了屏幕底部相对布局的高度

java - android构建错误: can't find symbol class IntDef

android - 将 FragmentPagerAdapter 设置为 ViewPager 以编程方式添加 fragment

java - 让Java中的方法返回在内部类中初始化的变量

android - 两个方向 ScrollView 内元素的固定位置

android - 如何在没有 Android 工具栏的 Fragment 中视差滚动布局到另一个布局

java - Android RealmList<Integer> 和 RealmList<String>