首页 > 解决方案 > 顶部的Android视图ScrollView LinearLayout

问题描述

我想获得巨大的视野,我必须滚动。我想在我的代码中始终在电话屏幕上获得一部分视图是 LinearLayout我想始终在屏幕上显示。放入我的LinearLayout位置 layout_alignParentTop,但当我滚动时它消失了。

我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/cor"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

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

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true">

                    <ImageView
                        android:id="@+id/iv_photo"
                        android:layout_width="0sp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />

                    <RelativeLayout
                        android:layout_width="0sp"
                        android:layout_height="wrap_content"
                        android:layout_weight="3.5">

                        <TextView
                            android:id="@+id/tv_user_name"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Jan Nowak"
                            android:textColor="@color/background_tutorial"
                            android:textSize="@dimen/text_normal_size"
                            android:textStyle="bold" />

                        <TextView
                            android:id="@+id/tv_user_mail"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/tv_user_name"
                            android:text="jan.nowak@gmail.com"
                            android:textColor="@color/background_tutorial"
                            android:textSize="@dimen/text_normal_size" />

                    </RelativeLayout>

                    <ImageView
                        android:id="@+id/iv_settings"
                        android:layout_width="0sp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" />
                </LinearLayout>

            </RelativeLayout>

        </RelativeLayout>

    </ScrollView>

</RelativeLayout>

标签: android

解决方案


做了一些改动:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cor"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        >

        <ImageView
            android:id="@+id/iv_photo"
            android:layout_width="0sp"
            android:layout_height="match_parent"
            android:layout_weight="1" />

        <RelativeLayout
            android:layout_width="0sp"
            android:layout_height="wrap_content"
            android:layout_weight="3.5">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/tv_user_name"
                android:textColor="#000000"
                android:textSize="17sp"
                android:text="Jan Nowak"
                android:textStyle="bold"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/tv_user_name"
                android:id="@+id/tv_user_mail"
                android:textColor="#000000"
                android:textSize="17sp"
                android:text="jan.nowak@gmail.com"
                />

        </RelativeLayout>

        <ImageView
            android:id="@+id/iv_settings"
            android:layout_width="0sp"
            android:layout_height="match_parent"
            android:layout_weight="1" />
    </LinearLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

        </RelativeLayout>
    </ScrollView>



</RelativeLayout>

如果您想保持视图静态和其他可滚动并将该视图保持在滚动视图之外......


推荐阅读