无法使 UI 可滚动
Can't make UI Scrollable
我正在尝试为 Android 应用程序登录 Activity。应用程序在 Potrait 模式下运行良好,但在横向模式下,UI 无法完全容纳,因此 UI 的一部分不是 visible.I 提到了所有相关的 SO 问题,但 none 有帮助。
设备- Motorola X Style Marshmallow
activity_login.xml
的代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SignupActivity"
android:scrollbars="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyMaterialTheme.AppBarOverlay">
<include android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="@layout/toolbar" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_login" />
</android.support.design.widget.CoordinatorLayout>
content_login.xml
的代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:background="#1E1E24"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".SignupActivity"
tools:showIn="@layout/activity_login">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/first"
android:textColor="@color/primary_text_default_material_dark"
android:textSize="@dimen/title_font"
android:textStyle="bold"
android:layout_marginBottom="@dimen/padding_10"
android:text="Login Activity"
/>
<View
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_below="@id/first"
android:layout_height="@dimen/contacting_post_staff_view_width"
android:background="@color/photo_border"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/third"
android:layout_below="@id/second"
android:textColor="@color/primary_text_default_material_dark"
android:textSize="@dimen/sub_title_font"
android:textStyle="bold"
android:layout_marginTop="@dimen/padding_10"
android:text="Hey ! This is a sample App for Login Activity"
/>
<LinearLayout
android:layout_marginTop="@dimen/fragment_main_marginTop_35"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_below="@id/third"
android:layout_height="wrap_content">
<EditText
android:background="@drawable/edit_text_bg"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15"
android:layout_height="wrap_content"
android:id="@+id/edit_name"
android:hint="@string/enter_name"
android:inputType="textPersonName|textCapWords" />
<Spinner
android:id="@+id/spinner_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dropDownWidth="@dimen/contacting_post_staff_spinner_width"
android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15" />
<Button
android:id="@+id/loginButton"
style="@style/NavigateButton"
android:text="@string/login"
android:layout_marginTop="@dimen/fragment_main_marginTop_35"/>
</LinearLayout>
</RelativeLayout>
toolbar.xml
的代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:background="@color/background_textview"
android:minHeight="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
</android.support.v7.widget.Toolbar>
为了解决这个问题,我试图使 UI 可滚动,以便用户可以滚动到横向模式下不可见的部分。
我试过的 -
1. 我试过将下面放在 Scrollview
include layout="@layout/content_login" />
2 我试过将上面放在线性布局中,然后将线性布局放在滚动视图中。
我玩过很多其他东西,但 none 帮助了我。
请多多帮助this.Thanks
尝试将 content_login.xml 的根元素设为 ScrollView
。
您可以在新的滚动视图中使用当前相对布局进行嵌套布局。
或者,您可以使用 AndroidManifest.xml 中 activity 标签下的 android:screenOrientation="portrait"
将 activity 的方向固定为 portrait
,如果这不是问题的话.
此外,考虑使用 ConstraintLayout
,它消除了处理嵌套布局的麻烦。
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SignupActivity">
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".SignupActivity"
android:orientation="vertical"
tools:showIn="@layout/activity_login">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/first"
android:textColor="@color/primary_text_default_material_dark"
android:textSize="@dimen/title_font"
android:textStyle="bold"
android:layout_marginBottom="@dimen/padding_10"
android:text="Login Activity"
/>
<View
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_below="@id/first"
android:layout_height="@dimen/contacting_post_staff_view_width"
android:background="@color/photo_border"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/third"
android:layout_below="@id/second"
android:textColor="@color/primary_text_default_material_dark"
android:textSize="@dimen/sub_title_font"
android:textStyle="bold"
android:layout_marginTop="@dimen/padding_10"
android:text="Hey ! This is a sample App for Login Activity"
/>
<LinearLayout
android:layout_marginTop="@dimen/fragment_main_marginTop_35"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_below="@id/third"
android:layout_height="wrap_content">
<EditText
android:background="@drawable/edit_text_bg"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15"
android:layout_height="wrap_content"
android:id="@+id/edit_name"
android:hint="@string/enter_name"
android:inputType="textPersonName|textCapWords" />
<Spinner
android:id="@+id/spinner_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dropDownWidth="@dimen/contacting_post_staff_spinner_width"
android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15" />
<Button
android:id="@+id/loginButton"
style="@style/NavigateButton"
android:text="@string/login"
android:layout_marginTop="@dimen/fragment_main_marginTop_35"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
试试这个,根据需要添加所有填充、边距、高度、宽度等以及所有布局约束
我正在尝试为 Android 应用程序登录 Activity。应用程序在 Potrait 模式下运行良好,但在横向模式下,UI 无法完全容纳,因此 UI 的一部分不是 visible.I 提到了所有相关的 SO 问题,但 none 有帮助。
设备- Motorola X Style Marshmallow
activity_login.xml
的代码<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SignupActivity"
android:scrollbars="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MyMaterialTheme.AppBarOverlay">
<include android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="@layout/toolbar" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_login" />
</android.support.design.widget.CoordinatorLayout>
content_login.xml
的代码<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:background="#1E1E24"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".SignupActivity"
tools:showIn="@layout/activity_login">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/first"
android:textColor="@color/primary_text_default_material_dark"
android:textSize="@dimen/title_font"
android:textStyle="bold"
android:layout_marginBottom="@dimen/padding_10"
android:text="Login Activity"
/>
<View
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_below="@id/first"
android:layout_height="@dimen/contacting_post_staff_view_width"
android:background="@color/photo_border"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/third"
android:layout_below="@id/second"
android:textColor="@color/primary_text_default_material_dark"
android:textSize="@dimen/sub_title_font"
android:textStyle="bold"
android:layout_marginTop="@dimen/padding_10"
android:text="Hey ! This is a sample App for Login Activity"
/>
<LinearLayout
android:layout_marginTop="@dimen/fragment_main_marginTop_35"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_below="@id/third"
android:layout_height="wrap_content">
<EditText
android:background="@drawable/edit_text_bg"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15"
android:layout_height="wrap_content"
android:id="@+id/edit_name"
android:hint="@string/enter_name"
android:inputType="textPersonName|textCapWords" />
<Spinner
android:id="@+id/spinner_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dropDownWidth="@dimen/contacting_post_staff_spinner_width"
android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15" />
<Button
android:id="@+id/loginButton"
style="@style/NavigateButton"
android:text="@string/login"
android:layout_marginTop="@dimen/fragment_main_marginTop_35"/>
</LinearLayout>
</RelativeLayout>
toolbar.xml
的代码<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/toolbar"
android:background="@color/background_textview"
android:minHeight="?attr/actionBarSize"
android:fitsSystemWindows="true"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
</android.support.v7.widget.Toolbar>
为了解决这个问题,我试图使 UI 可滚动,以便用户可以滚动到横向模式下不可见的部分。
我试过的 -
1. 我试过将下面放在 Scrollview
include layout="@layout/content_login" />
2 我试过将上面放在线性布局中,然后将线性布局放在滚动视图中。
我玩过很多其他东西,但 none 帮助了我。
请多多帮助this.Thanks
尝试将 content_login.xml 的根元素设为 ScrollView
。
您可以在新的滚动视图中使用当前相对布局进行嵌套布局。
或者,您可以使用 AndroidManifest.xml 中 activity 标签下的 android:screenOrientation="portrait"
将 activity 的方向固定为 portrait
,如果这不是问题的话.
此外,考虑使用 ConstraintLayout
,它消除了处理嵌套布局的麻烦。
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SignupActivity">
<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".SignupActivity"
android:orientation="vertical"
tools:showIn="@layout/activity_login">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/first"
android:textColor="@color/primary_text_default_material_dark"
android:textSize="@dimen/title_font"
android:textStyle="bold"
android:layout_marginBottom="@dimen/padding_10"
android:text="Login Activity"
/>
<View
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_below="@id/first"
android:layout_height="@dimen/contacting_post_staff_view_width"
android:background="@color/photo_border"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/third"
android:layout_below="@id/second"
android:textColor="@color/primary_text_default_material_dark"
android:textSize="@dimen/sub_title_font"
android:textStyle="bold"
android:layout_marginTop="@dimen/padding_10"
android:text="Hey ! This is a sample App for Login Activity"
/>
<LinearLayout
android:layout_marginTop="@dimen/fragment_main_marginTop_35"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_below="@id/third"
android:layout_height="wrap_content">
<EditText
android:background="@drawable/edit_text_bg"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15"
android:layout_height="wrap_content"
android:id="@+id/edit_name"
android:hint="@string/enter_name"
android:inputType="textPersonName|textCapWords" />
<Spinner
android:id="@+id/spinner_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dropDownWidth="@dimen/contacting_post_staff_spinner_width"
android:layout_marginTop="@dimen/contacting_post_staff_marginTop_15" />
<Button
android:id="@+id/loginButton"
style="@style/NavigateButton"
android:text="@string/login"
android:layout_marginTop="@dimen/fragment_main_marginTop_35"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
试试这个,根据需要添加所有填充、边距、高度、宽度等以及所有布局约束