如何在滚动视图内的屏幕底部对齐 textview android
How to align textview at the bottom of the screen inside a scroll view android
我正在设计一个包含以下项目的登录屏幕
Logo
User Name
Password
4.Login Button
- Copyright
下面是我尝试实现的相同布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/ActivityStyle"
android:orientation="vertical"
tools:context=".abc.ui.main.login.view.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical">
<RelativeLayout
android:id="@+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<ImageView
android:id="@+id/img_abc_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="@mipmap/abc_logo" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/img_abc_logo"
android:layout_marginTop="80dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
android:id="@+id/edit_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:paddingTop="10dp"
android:singleLine="true"
android:textColor="@color/fontColor"
android:textColorHint="@color/copy_right_font_color" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
android:id="@+id/edit_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="@+id/login"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/fontColor"
android:textColorHint="@color/copy_right_font_color" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/button_login"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:height="55dp"
android:text="@string/action_sign_in"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
<TextView
style="@style/CopyRightTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingTop="30dp"
android:text="@string/copy_right_text" />
我的要求
- Log should be at the top
- User name ,password and login button should be at the center of screen
- Copyright at the bottom
面临的问题
由于我使用的是滚动视图,因此无法填充高度。我尝试使用 android:fillViewport="true" 但我的滚动条 disappear.So 我无法将登录输入和按钮置于中心
出现键盘时,版权信息出现在登录按钮上方
在你的 TextView 中删除
android:layout_alignParentBottom="true"
添加
android:layout_below="@+id/linearLayout"
TextView 在 RelativeLayout.like 里面移动
<TextView
style="@style/CopyRightTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout"
android:layout_centerHorizontal="true"
android:paddingTop="30dp"
android:text="@string/copy_right_text" />
</RelativeLayout>
</ScrollView>
把这个放在你的 activity 边上 onCreate 方法
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
或
在您的活动清单中:
android:windowSoftInputMode="adjustPan"
正如你所说的在 scrollview 里面把它放在 relative layout
<TextView
style="@style/CopyRightTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout"
android:layout_centerHorizontal="true"
android:paddingTop="30dp"
android:text="@string/copy_right_text" />
</RelativeLayout>
</ScrollView>
我正在设计一个包含以下项目的登录屏幕
Logo
User Name
Password 4.Login Button
- Copyright
下面是我尝试实现的相同布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/ActivityStyle"
android:orientation="vertical"
tools:context=".abc.ui.main.login.view.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="@+id/login_progress"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical">
<RelativeLayout
android:id="@+id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<ImageView
android:id="@+id/img_abc_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="@mipmap/abc_logo" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/img_abc_logo"
android:layout_marginTop="80dp"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
android:id="@+id/edit_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:paddingTop="10dp"
android:singleLine="true"
android:textColor="@color/fontColor"
android:textColorHint="@color/copy_right_font_color" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
android:id="@+id/edit_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="@+id/login"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/fontColor"
android:textColorHint="@color/copy_right_font_color" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@+id/button_login"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:height="55dp"
android:text="@string/action_sign_in"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
<TextView
style="@style/CopyRightTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingTop="30dp"
android:text="@string/copy_right_text" />
我的要求
- Log should be at the top
- User name ,password and login button should be at the center of screen
- Copyright at the bottom
面临的问题
由于我使用的是滚动视图,因此无法填充高度。我尝试使用 android:fillViewport="true" 但我的滚动条 disappear.So 我无法将登录输入和按钮置于中心
出现键盘时,版权信息出现在登录按钮上方
在你的 TextView 中删除
android:layout_alignParentBottom="true"
添加
android:layout_below="@+id/linearLayout"
TextView 在 RelativeLayout.like 里面移动
<TextView
style="@style/CopyRightTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout"
android:layout_centerHorizontal="true"
android:paddingTop="30dp"
android:text="@string/copy_right_text" />
</RelativeLayout>
</ScrollView>
把这个放在你的 activity 边上 onCreate 方法
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
或 在您的活动清单中:
android:windowSoftInputMode="adjustPan"
正如你所说的在 scrollview 里面把它放在 relative layout
<TextView
style="@style/CopyRightTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout"
android:layout_centerHorizontal="true"
android:paddingTop="30dp"
android:text="@string/copy_right_text" />
</RelativeLayout>
</ScrollView>