开发者

How can I put all of my layouts and UI inside of a ScrollView?

开发者 https://www.devze.com 2023-03-13 08:58 出处:网络
I have a really long layout with tons of layouts etc. How can I wrap it all inside of a scrollview so the user can scroll when it runs out of room? I only want the stuff below \"borderSeperator\" to b

I have a really long layout with tons of layouts etc. How can I wrap it all inside of a scrollview so the user can scroll when it runs out of room? I only want the stuff below "borderSeperator" to be scrollable.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent" android:layout_width="wrap_content">
   <RelativeLayout android:id="@+id/actionbarRelativeLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/actionbar_gradient">
        <ImageButton android:id="@+id/stocktwitsImageButton" android:layout_width="wrap_content" android:background="@drawable/stocktwits" android:layout_height="wrap_content"></ImageButton>
        <ImageButton android:layout_width="wrap_content" android:id="@+id/composeImageButton" android:layout_alignParentRight="true" android:layout_height="wrap_content" android:background="@drawable/composebutton"></ImageButton>
    </RelativeLayout>
   <RelativeLayout
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:id="@+id/headerLinearLay"
    android:orientation="horizontal" android:background="#e8e8e8" android:padding="8px">
        <ImageView
        android:id="@+id/avatarImageView"
        android:layout_height="48px" android:layout_width="48px"></ImageView>
        <LinearLayout android:id="@+id/linearLayout3" android:layout_toRightOf="@+id/avatarImageView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginLeft="4dp">
            <TextView android:text="TextView" android:textColor="#000000" android:textStyle="bold" android:id="@+id/nameTextView" android:layout_height="wrap_content" android:layout_width="fill_parent">    </TextView>
            <TextView android:text="TextView" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/usernameTextView" android:textColor="#000000"></TextView>
        </LinearLayout>
    </RelativeLayout>
   <LinearLayout android:layout_height="1dp" android:layout_width="fill_parent" android:id="@+id/borderSeperator" android:background="#c4c4c4"></LinearLayout>
    <TextView android:layout_height="wrap_content" android:textSize="24sp" android:layout_width="fill_parent" android:autoLink="web" android:textColor="#000000" android:background="#ffffff" android:padding="8dp" android:id="@+id/bioLabel" android:text="Bio"></TextView>
    <TextView android:padding="8dp" android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="fill_parent" android:textColor="#000000" android:background="#ffffff" android:id="@+id/bioTextView"></TextView>
    <LinearLayout android:layout_width="fill_parent" android:layout_height="1dp" android:background="#c4c4c4" android:id="@+id/bioSeperator"></LinearLayout>
    <TextView android:padding="8dp" android:layout_height="wrap_content" android:textSize="24sp" android:layout_width="fill_parent" android:textColor="#000000" android:autoLink="web" android:background="#ffffff" android:id="@+id/locationLabel" android:text="Location"></TextView>
    <TextView android:padding="8dp" android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="fill_parent" android:textColor="#000000" android:background="#ffffff" android:id="@+id/locationTextView"></TextView>
    <LinearLayout android:layout_width="fill_parent" android:layout_height="1dp" android:background="#c4c4c4" android:id="@+id/locationSeperator"></LinearLayout>
    <TextView android:padding="8dp" android:layout_height="wrap_content" android:textSize="24sp" android:layout_width="fill_parent" android:textColor="#000000" android:autoLink="web" android:background="#ffffff" android:id="@+id/websiteLabel" android:text="Website"></TextView>
    <TextView android:padding="8dp" android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="fill_parent" android:textColor="#000000" android:background="#ffffff" android:id="@+id/websiteTextView"></TextView>
    <LinearLayout android:layout_wid开发者_Go百科th="fill_parent" android:layout_height="1dp" android:background="#c4c4c4" android:id="@+id/websiteSeperator"></LinearLayout>
    <LinearLayout android:id="@+id/experienceLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#ffffff" android:layout_weight="1">
        <TextView android:text="Experience" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:textColor="#000000" android:textStyle="bold" android:id="@+id/experienceLabel"></TextView>
        <TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content" android:textColor="#000000" android:id="@+id/experienceTextView"></TextView>
    </LinearLayout>
    <LinearLayout android:id="@+id/assetsLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#ffffff" android:layout_weight="1">
        <TextView android:text="Assets Traded" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:textColor="#000000" android:textStyle="bold" android:id="@+id/assetsLabel"></TextView>
        <TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content" android:textColor="#000000" android:id="@+id/assetsTextView"></TextView>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#ffffff" android:layout_weight="1" android:id="@+id/approachLayout">
        <TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:textColor="#000000" android:textStyle="bold" android:id="@+id/approachLabel" android:text="Approach"></TextView>
        <TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content" android:textColor="#000000" android:id="@+id/approachTextView"></TextView>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#ffffff" android:layout_weight="1" android:id="@+id/riskLayout">
        <TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:textColor="#000000" android:textStyle="bold" android:id="@+id/riskLabel" android:text="Risk Profile"></TextView>
        <TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content" android:textColor="#000000" android:id="@+id/riskTextView"></TextView>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:background="#ffffff" android:layout_weight="1" android:id="@+id/holdingPeriodLayout">
        <TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="wrap_content" android:textColor="#000000" android:textStyle="bold" android:id="@+id/holdingPeriodLabel" android:text="Holding Period"></TextView>
        <TextView android:text="TextView" android:layout_height="wrap_content" android:layout_weight="0" android:layout_width="wrap_content" android:textColor="#000000" android:id="@+id/holdingPeriodTextView"></TextView>
    </LinearLayout>
</LinearLayout>


Here's a good example of ScrollView It's pretty self explanatory once you look at how they go through it.

The content occurring below your LinearLayout with @+id/borderSeperator (note: which has the </LinearLayout> on the same line) should all be contained inside its own LinearLayout and put inside the ScrollView


In your outer LinearLayout, change its height to wrap_content then simply put it inside of a ScrollView with height and width as fill_parent.


Create a LinearLayout with just a ScrollView in it and put your current top level layout in the scrollview

<LinearLayout>
    <ScrollView>
       ...layoutyou have now
    </ScrollView>
</LinearLayout>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号