简体   繁体   English

使LinearLayouts在Android中可滚动

[英]Making linearlayouts scrollable in android

I am making an android application that needs to use a scrollable layout that contains a couple of linearlayouts, a textview and a listview. 我正在制作一个需要使用可滚动布局的android应用程序,该布局包含几个linearlayouts,一个textview和一个listview。 How can i make this happen??? 我怎样才能做到这一点??? Please help and thanks SO much in advance! 请帮助,并非常感谢! This is the xml code that i am using so far: 这是我到目前为止使用的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >




<TextView
    android:id="@+id/NotesWelcomeTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/NotesWelcomeText" />








<ListView
    android:id="@+android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

</ListView>


<LinearLayout
    android:id="@+id/DeleteAllItemsFromListViewLinearLayout"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:visibility="invisible" >


    <Button
        android:id="@+id/CancelButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Cancel" />


    <Button
        android:id="@+id/DeleteAllButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Delete" />

</LinearLayout>


<LinearLayout
    android:id="@+id/DeleteItemFromListViewLinearLayout"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:visibility="invisible" >


    <Button
        android:id="@+id/CancelButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Cancel" />


    <Button
        android:id="@+id/DeleteButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/Delete" />

</LinearLayout>




<LinearLayout
    android:id="@+id/AddItemToListViewLinearLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:visibility="gone" >



    <EditText
        android:id="@+id/AddItemToListViewEditText"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </EditText>



    <Button
        android:id="@+id/AddItemToListViewButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/Add" />

</LinearLayout>

</LinearLayout>
 <ScrollView
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"
     android:fillViewport="true">   
<TextView 
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:singleLine="false"
     android:text="@string/terms_and_conditions" />
</ScrollView>

Make your main layout as scroll layout inside that put the linear layout. 使您的主布局为滚动布局,然后将线性布局放入其中。

Keep in mind Scroll layout can hold only one type of item... 请记住,滚动版式只能容纳一种类型的项目...

Once you do this, the whole layout is scroll able up and down or left and right as per your XML config. 完成此操作后,整个布局就可以根据您的XML配置上下左右滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM