简体   繁体   English

如何在android中添加scrollview?

[英]how to add scrollview in android?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/list_bg"
    android:paddingLeft="57dip" >

    <RelativeLayout
        android:id="@+id/menu_header_relay"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/selection_bar" >

        <TextView
            android:id="@+id/header_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20dip"
            android:text="@string/show_only"
            android:textSize="20sp" />
    </RelativeLayout>


    <LinearLayout
        android:id="@+id/fav_listview"
        android:layout_width="fill_parent"
        android:layout_height="200dip"
        android:layout_below="@+id/menu_header_relay"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/couple_layout"
            android:layout_width="fill_parent"
            android:layout_height="60dip"
            android:gravity="center_vertical" >

            <ImageView
                android:id="@+id/right_couple_IV"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dip"
                android:background="@drawable/right_mark"
                android:visibility="invisible" />

            <TextView
                android:id="@+id/couple_textview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="50dip"
                android:layout_toRightOf="@id/icon_IV"
                android:text="COUPLE FAV"
                android:textColor="@android:color/white"
                android:textSize="20sp" />

        </RelativeLayout>

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/divider_line" />

        <RelativeLayout
            android:id="@+id/mine_layout"
            android:layout_width="fill_parent"
            android:layout_height="60dip"
            android:gravity="center_vertical" >

            <ImageView
                android:id="@+id/right_mine_IV"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dip"
                android:background="@drawable/right_mark"
                android:visibility="invisible" />

            <TextView
                android:id="@+id/mine_textview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="50dip"
                android:layout_toRightOf="@id/icon_IV"
                android:text="MINE FAV"
                android:textColor="@android:color/white"
                android:textSize="20sp" />
        </RelativeLayout>

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/divider_line" />

        <RelativeLayout
            android:id="@+id/all_layout"
            android:layout_width="fill_parent"
            android:layout_height="60dip"
            android:gravity="center_vertical" >

            <ImageView
                android:id="@+id/right_all_IV"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dip"
                android:background="@drawable/right_mark"
                android:visibility="invisible" />

            <TextView
                android:id="@+id/all_textview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="50dip"
                android:layout_toRightOf="@id/icon_IV"
                android:text="ALL FAV"
                android:textColor="@android:color/white"
                android:textSize="20sp" />
        </RelativeLayout>

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/divider_line" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/category_relay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/fav_listview"
        android:background="@drawable/selection_bar" >

        <TextView
            android:id="@+id/Category_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20dip"
            android:text="@string/categories"
            android:textSize="20sp" />

        <ImageButton
            android:id="@+id/editor_IB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dip"
            android:background="@drawable/editar_btn" />
    </RelativeLayout>

 <!-- >    <ListView
        android:id="@+id/right_category_listview"
        android:layout_width="fill_parent"
        android:layout_height="200dip"
        android:layout_below="@+id/category_relay"
        android:cacheColorHint="#00000000"
        android:divider="@drawable/menu_divider_line"
        android:dividerHeight="5dip"
        android:fadeScrollbars="false" >
    </ListView>-->

<RelativeLayout
    android:id="@+id/recepcion_layout"
    android:layout_width="fill_parent"
    android:layout_height="60dip"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/category_relay"
    android:gravity="center_vertical" >

    <ImageView
        android:id="@+id/right_recepcion_IV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:background="@drawable/right_mark"
        android:visibility="invisible" />

    <TextView
        android:id="@+id/recepcion_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dip"
        android:layout_toRightOf="@id/icon_IV"
        android:text="RECEPCION"
        android:textColor="@android:color/white"
        android:textSize="20sp" />
</RelativeLayout>
<ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/divider_line" />
<RelativeLayout
    android:id="@+id/ceremonia_layout"
    android:layout_width="fill_parent"
    android:layout_height="60dip"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/recepcion_layout"
    android:gravity="center_vertical" >

    <ImageView
        android:id="@+id/right_ceremonia_IV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:background="@drawable/right_mark"
        android:visibility="invisible" />

    <TextView
        android:id="@+id/ceremonia_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dip"
        android:layout_toRightOf="@id/icon_IV"
        android:text="CEREMONIA"
        android:textColor="@android:color/white"
        android:textSize="20sp" />
</RelativeLayout>
<ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/divider_line" />

<RelativeLayout
    android:id="@+id/divertidas_layout"
    android:layout_width="fill_parent"
    android:layout_height="60dip"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/ceremonia_layout"
    android:gravity="center_vertical" >

    <ImageView
        android:id="@+id/right_divertidas_IV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:background="@drawable/right_mark"
        android:visibility="invisible" />

    <TextView
        android:id="@+id/divertidas_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dip"
        android:layout_toRightOf="@id/icon_IV"
        android:text="DIVERTIDAS"
        android:textColor="@android:color/white"
        android:textSize="20sp" />
</RelativeLayout>
<ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/divider_line" />

<RelativeLayout
    android:id="@+id/familia_layout"
    android:layout_width="fill_parent"
    android:layout_height="60dip"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/ceremonia_layout"
    android:gravity="center_vertical" >

    <ImageView
        android:id="@+id/right_familia_IV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:background="@drawable/right_mark"
        android:visibility="invisible" />

    <TextView
        android:id="@+id/familia_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dip"
        android:layout_toRightOf="@id/icon_IV"
        android:text="FAMILIA"
        android:textColor="@android:color/white"
        android:textSize="20sp" />
    </RelativeLayout>


          </RelativeLayout>

in my layout,i want to scroll my items in relative layout without scrooling their header ,when i scroll it so my header sholudnot move and layout sholudnot bad,how can i do this?is therir any solution,i have tried so muxh things but it says relatuive layout must only one siblings. 在我的布局中,我想在相对布局中滚动我的项目而不会破坏其标题,当我滚动它以便标题不移动且布局不正确时,我该怎么办?这是任何解决方案吗,我尝试了很多它说相对布局只允许一个兄弟姐妹。

只能在滚动视图中放一个孩子。

Go this way 走这边

<Linear/RelativeLayout>
  <Linear/RelativeLayout>
    <!-- Your Custom Header or anything you want to display which should remain fix -->
  </Linear/RelativeLayout> 
  <ScrollView>
     <Linear/RelativeLayout>
     </Linear/RelativeLayout>
  <ScrollView>
</Linear/RelativeLayout>

In one ScrollView can be one RelativeLayout. 在一个ScrollView中可以是一个RelativeLayout。

Try something like this: 尝试这样的事情:

<ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >


        <TextView
          android:id="@+id/tv"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
           />

     </RelativeLayout>
</ScrollView>

It works for me. 这个对我有用。 you just have to put the scrollview on right position, but I can't do that for you. 您只需要将scrollview放在正确的位置即可,但是我不能为您做到这一点。

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

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