我想在我的布局中添加滚动但是当我这样做时它给了我多余的滚动

时间:2017-01-09 09:37:04

标签: android android-layout

This is the output i am getting i want it to look normal and with a scroll view wrapping this content这是login.xml的布局文件,但是当我在纵向模式下看到这个时,这对我来说很好,但是当我这样做是肖像时它会给出多余的滚动< / p>

       <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:fillViewport="true">

<!-- Relative layout defined for the view and components -->
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/login_activity_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/bgimagelogin"
            tools:context="com.example.a129346.applicationpoc.activities.LoginActivity">

             <TextView
                android:id="@+id/app_name_tv"
                android:text="@string/lexus_string"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:textColor="@color/colorPeace"
                android:layout_marginLeft="@dimen/aligned_text_side_marginleft"
                android:layout_marginTop="@dimen/aligned_text_side_marginTop"
                android:textSize="@dimen/size_text" />

            <TextView
                android:id="@+id/join_now_tv"
                android:text="@string/new_user"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="24dp"
                android:textColor="@color/colorPeace"
                android:layout_below="@+id/login_bt"
                android:layout_alignEnd="@+id/password_et" />

            <EditText
                android:id="@+id/username_et"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:hint="@string/person_name"
                android:ems="10"
                android:textColor="@color/colorPeace"
                android:drawableLeft="@drawable/person_mdpi"
                android:layout_below="@+id/app_name_tv"
                android:layout_alignStart="@+id/app_name_tv"
                android:layout_marginTop="12dp" />

            <EditText
                android:id="@+id/password_et"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:ems="10"
                android:drawableLeft="@drawable/lock_mdpi"
                android:hint="@string/password_string"
                android:textColor="@color/colorPeace"
                android:layout_below="@+id/username_et"
                android:layout_alignStart="@+id/username_et"
                android:layout_marginTop="17dp" />

            <CheckBox
                android:id="@+id/remember_me_cb"
                android:text="@string/checkbox_me"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/colorPeace"
                android:layout_alignBaseline="@+id/forgotText2"
                android:layout_alignBottom="@+id/forgotText2"
                android:layout_alignParentEnd="true" />
        <!--text for the forget password-->
            <TextView
                android:id="@+id/forgotText2"
                android:text="@string/text_password_forgot"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="31dp"
                android:textColor="@color/colorPeace"
                android:layout_below="@+id/password_et"
                android:layout_toStartOf="@+id/join_now_tv" />
        <!--Button for the login-->
            <Button
                android:id="@+id/login_bt"
                android:text="@string/button_string"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:background="@color/colorButton"
                android:layout_below="@+id/remember_me_cb"
                android:layout_alignEnd="@+id/join_now_tv"
                android:layout_alignStart="@+id/password_et" />
        <!--Image view for icon-->
            <ImageView
                android:id="@+id/app_icon_iv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_header_icon"
                android:layout_marginLeft="@dimen/aligned_icon_side_marginleft"
                android:layout_marginBottom="48dp"
                android:layout_above="@+id/username_et"
                android:layout_alignEnd="@+id/forgotText2" />



        </RelativeLayout>
        </ScrollView>

这是登录页面的总布局。

我想在我的布局中添加滚动,但是当我正在执行此代码时,它滚动得更多,滚动所有页面我只想滚动我的组件或适合屏幕。

1 个答案:

答案 0 :(得分:0)

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:fillViewport="true">

<!-- Relative layout defined for the view and components -->
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/login_activity_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/bgimagelogin"
            tools:context="com.example.a129346.applicationpoc.activities.LoginActivity">

             <TextView
                android:id="@+id/app_name_tv"
                android:text="@string/lexus_string"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="5"
                android:textColor="@color/colorPeace"
                android:layout_marginLeft="@dimen/aligned_text_side_marginleft"
                android:layout_marginTop="@dimen/aligned_text_side_marginTop"
                android:textSize="@dimen/size_text" />

            <TextView
                android:id="@+id/join_now_tv"
                android:text="@string/new_user"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="24dp"
                android:textColor="@color/colorPeace"
                android:layout_below="@+id/login_bt"
                android:layout_alignEnd="@+id/password_et" />

            <EditText
                android:id="@+id/username_et"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:hint="@string/person_name"
                android:ems="10"
                android:textColor="@color/colorPeace"
                android:drawableLeft="@drawable/person_mdpi"
                android:layout_below="@+id/app_name_tv"
                android:layout_alignStart="@+id/app_name_tv"
                android:layout_marginTop="12dp" />

            <EditText
                android:id="@+id/password_et"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:ems="10"
                android:drawableLeft="@drawable/lock_mdpi"
                android:hint="@string/password_string"
                android:textColor="@color/colorPeace"
                android:layout_below="@+id/username_et"
                android:layout_alignStart="@+id/username_et"
                android:layout_marginTop="17dp" />

            <CheckBox
                android:id="@+id/remember_me_cb"
                android:text="@string/checkbox_me"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/colorPeace"
                android:layout_alignBaseline="@+id/forgotText2"
                android:layout_alignBottom="@+id/forgotText2"
                android:layout_alignParentEnd="true" />
        <!--text for the forget password-->
            <TextView
                android:id="@+id/forgotText2"
                android:text="@string/text_password_forgot"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="31dp"
                android:textColor="@color/colorPeace"
                android:layout_below="@+id/password_et"
                android:layout_toStartOf="@+id/join_now_tv" />
        <!--Button for the login-->
            <Button
                android:id="@+id/login_bt"
                android:text="@string/button_string"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="12dp"
                android:background="@color/colorButton"
                android:layout_below="@+id/remember_me_cb"
                android:layout_alignEnd="@+id/join_now_tv"
                android:layout_alignStart="@+id/password_et" />
        <!--Image view for icon-->
            <ImageView
                android:id="@+id/app_icon_iv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_header_icon"
                android:layout_marginLeft="@dimen/aligned_icon_side_marginleft"
                android:layout_marginBottom="48dp"
                android:layout_above="@+id/username_et"
                android:layout_alignEnd="@+id/forgotText2" />



        </RelativeLayout>
        </ScrollView>

用此替换您的代码。