Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如果ScrollView只支持一个直接子级,我该如何使整个布局可滚动?_Android_Xml_Formatting_Scrollview_Dimensions - Fatal编程技术网

Android 如果ScrollView只支持一个直接子级,我该如何使整个布局可滚动?

Android 如果ScrollView只支持一个直接子级,我该如何使整个布局可滚动?,android,xml,formatting,scrollview,dimensions,Android,Xml,Formatting,Scrollview,Dimensions,我在一个布局中有3个文本视图,其中文本在我的Droid2的底部有一点剪辑。。。我如何确保整个文本都是可见的,用户可以向下滚动(只需用手指)来查看我的其余文本 谢谢 编辑: ScrollView的直接子级应该是另一个支持多个子级的布局,例如RelativeLayout或LinearLayout。只需使用ScrollView包装当前的LinearLayout即可。所以应该是这样的smth: <?xml version="1.0" encoding="utf-8"?> <Scrol

我在一个布局中有3个文本视图,其中文本在我的Droid2的底部有一点剪辑。。。我如何确保整个文本都是可见的,用户可以向下滚动(只需用手指)来查看我的其余文本

谢谢

编辑:



ScrollView的直接子级应该是另一个支持多个子级的布局,例如RelativeLayout或LinearLayout。

只需使用ScrollView包装当前的LinearLayout即可。所以应该是这样的smth:

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

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

        <ImageButton ... />
        <TextView ... />
        <TextView ... />
        <TextView ... />

    </LinearLayout>
</ScrollView>

工作正常

下面是我的布局示例,它可以滚动上面有两个保持静止的标题的内容项

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/mainMenu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFFFFFF"
xmlns:android="http://schemas.android.com/apk/res/android"
>
    <FrameLayout
    android:id="@+id/widget112"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
        <ImageView
        android:id="@+id/chemo_pro_header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/chemo_pro_header"
        >
        </ImageView>
        <ImageButton
        android:id="@+id/menu_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/menu_btn_off"
        android:background="@null"
        android:layout_gravity="right"
        android:padding="8px"
        >
        </ImageButton>
    </FrameLayout>
    <ImageView 
    android:layout_width="wrap_content" 
    android:id="@+id/news_head"
    android:src="@drawable/news_head" 
    android:layout_height="wrap_content">
    </ImageView>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
            <TextView android:layout_marginLeft="6dip" android:text="Monday, November 29th, 2010" android:id="@+id/newsDateStamp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:typeface="serif" android:textStyle="italic" android:textColor="#ff999999"></TextView>
            <TextView android:layout_marginLeft="6dip" android:text="Normal Article Titles Fit on These Lines and have room to be this long" android:textSize="16sp" android:typeface="serif" android:textStyle="bold" android:textColor="#ff000000" android:id="@+id/newsTitle" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
            <TextView android:layout_marginLeft="6dip" android:text="Article source" android:id="@+id/newsSource" android:layout_width="wrap_content" android:layout_height="wrap_content" android:typeface="serif" android:textStyle="italic" android:textColor="#ff999999"></TextView>
            <ImageView 
            android:layout_width="wrap_content" 
            android:id="@+id/news_image"
            android:src="@drawable/news_image" 
            android:layout_height="wrap_content" android:layout_gravity="center">
            </ImageView>
            <TextView android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras in volutpat enim. Donec tempus vestibulum risus in pellentesque. Etiam eget lorem at velit facilisis dapibus.\n\nNunc dolor sem, semper vel vestibulum eu, ultrices tempus augue. Donec ligula erat, tempor dignissim imperdiet et, rutrum sed nisi. Praesent dignissim nulla ullamcorper metus facilisis auctor. Duis elementum commodo dictum. Duis rhoncus hendrerit lectus in tincidunt. Ut est neque, rutrum ut auctor ac, aliquet ut massa. Nullam at felis ipsum. Curabitur adipiscing sodales massa, sed lobortis lectus ultrices quis. Integer lobortis cursus tellus sed tempus. Ut convallis ullamcorper interdum. Integer iaculis feugiat ultricies.\n\nNunc dolor sem, semper vel vestibulum eu, ultrices tempus augue. Donec ligula erat, tempor dignissim imperdiet et, rutrum sed nisi. Praesent dignissim nulla ullamcorper metus facilisis auctor. Duis elementum commodo dictum. Duis rhoncus hendrerit lectus in tincidunt. Ut est neque, rutrum ut auctor ac, aliquet ut massa." android:layout_marginTop="6dip" android:layout_marginBottom="6dip" android:typeface="serif" android:id="@+id/newsBody" android:layout_marginLeft="6dip" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#ff000000" android:layout_marginRight="6dip"></TextView>
    </LinearLayout>
    </ScrollView>
</LinearLayout>

如果要滚动整个布局,只需将scrollview设置为父级,将线性布局或任何其他布局设置为第一个子级,然后在其中添加其他布局。。。。例如:

<Scrollview>
   <LinearLayout  android:id="@+id/child1">
     <Textview />
     <Textview />
     <Button />
     <LinearLayout>
       <Textview />
     </LinearLayout>
   </LinearLayout>
 </scrollview>


这里Scrollview只有一个子“child1”,其余的都在里面,因此整个布局是可滚动的。

我可以将整个flipper封装为Scrollview吗?我不这么认为,因为flipper本身不是您想要滚动的。您希望滚动翻转器成员的内容。记住,Android中的一些视图已经是可滚动的,最显著的是ListView;但是,如果您使用的是非滚动视图或画布,您应该为您的flipper分配多个滚动视图。我真的很困惑-我在xml中编辑,看看您是否可以告诉我,如果此布局对于屏幕来说太大,
LinearLayout
应该是
android:layou\u高度,那么需要做些什么才能使其可滚动=“包装内容”
而不是匹配父项
<Scrollview>
   <LinearLayout  android:id="@+id/child1">
     <Textview />
     <Textview />
     <Button />
     <LinearLayout>
       <Textview />
     </LinearLayout>
   </LinearLayout>
 </scrollview>