Android:将滚动视图位置设置为从屏幕顶部的80%开始

Android:将滚动视图位置设置为从屏幕顶部的80%开始,android,android-layout,Android,Android Layout,我正在努力实现这样的目标: - |-------------------|<-------Phone screen | ||-----------------|| | || || 80% || || | || || | || |<--------Image View (fills screen, background) - |||-

我正在努力实现这样的目标:

 -  |-------------------|<-------Phone screen
 |  ||-----------------||
 |  ||                 ||
80% ||                 ||
 |  ||                 ||
 |  ||                 |<--------Image View  (fills screen, background)
 -  |||---------------|||
 |  |||               |||
20% |||               |<---------Scroll View (starts after 80% of parent view)
 |  ||-----------------||
 -  |-------------------|  

————————————您需要一个线性布局,
android:orientation=“vertical”

然后为
ImageView
添加两个视图(
ImageView
ScrollView
),分别为
ImageView
添加
android:layout\u weight=“80”
,为
ScrollView添加

两者都必须具有android:layout\u height=“0dip”
,以确保只计算重量

XML代码如下所示(我使用了第二个ImageView而不是ScrollView以蓝色和红色显示结果)


您需要一个线性布局,
android:orientation=“vertical”

然后为
ImageView
添加两个视图(
ImageView
ScrollView
),分别为
ImageView
添加
android:layout\u weight=“80”
,为
ScrollView添加

两者都必须具有android:layout\u height=“0dip”
,以确保只计算重量

XML代码如下所示(我使用了第二个ImageView而不是ScrollView以蓝色和红色显示结果)


    使用
    布局和重量

    <RelativeLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    
    <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="8" />
    
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2">
    
            </ScrollView>
    
    </LinearLayout>
    
    </RelativeLayout>
    

    使用
    布局和重量

    <RelativeLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    
    <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="8" />
    
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2">
    
            </ScrollView>
    
    </LinearLayout>
    
    </RelativeLayout>
    
    
    
    jboi,谢谢。但是这不会把布局分成两半吗?80%是图像,20%是滚动视图?我希望imageview是背景,滚动视图在imageview的上方。@paypalcomp。我监督过那部分。实现背景图像的最简单方法是使用LinearLayout.jboi的
    android:background=“
    ,谢谢。但是这不会把布局分成两半吗?80%是图像,20%是滚动视图?我希望imageview是背景,滚动视图在imageview的上方。@paypalcomp。我监督过那部分。获取背景图像的最简单方法是使用LinearLayout.shem的
    android:background=“
    ,谢谢。但正如我对jboi的回答所评论的那样,这不会将布局分成两半吗?80%是图像,20%是滚动视图?我希望图像视图为背景,滚动视图位于图像视图上方。谢姆,谢谢。但正如我对jboi的回答所评论的那样,这不会将布局分成两半吗?80%是图像,20%是滚动视图?我希望imageview是背景视图,滚动视图位于imageview之上。
    <RelativeLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    
    <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="8" />
    
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2">
    
            </ScrollView>
    
    </LinearLayout>
    
    </RelativeLayout>