我试图创建用户界面的登录页面与徽标两个编辑文本和登录按钮,事情是非常好的手机肖像模式,但是当我检查它在景观和平板电脑,然后问题开始了。Android布局创建问题,而从相对和线性布局从纵向切换
我有两个解决方案
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayoutparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fed2db"
android:orientation="vertical"
>
<RelativeLayout
android:id="@+id/linearlayout_parents"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/relativelayoutbasic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin20"
android:layout_marginRight="@dimen/margin20"
android:layout_centerInParent="true"
>
<EditText
android:id="@+id/userName"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="[email protected]"
android:hint="UserName"
android:drawableStart="@mipmap/ic_launcher"
android:drawablePadding="10dp"
android:background="@null"
android:layout_marginTop="10dp" />
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#f7f7f7"
android:layout_below="@id/userName"
android:layout_marginTop="10dp" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/view"
android:inputType="textPassword"
android:hint="Password"
android:text="[email protected]"
android:drawablePadding="10dp"
android:background="@null"
android:drawableStart="@mipmap/ic_launcher"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/password"
android:background="#f7f7f7"
android:text="Login"
android:textColor="@android:color/black"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="17sp"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/buttonForgotPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/buttonLogin"
android:layout_marginTop="10dp"
android:text="Forgot Password ?"
android:textColor="@android:color/white"
android:textAllCaps="false"
android:background="@null" />
</RelativeLayout>
<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_marginTop="@dimen/margin20"
android:layout_above="@id/relativelayoutbasic"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
</RelativeLayout>
这部作品在纵向模式完美,但正如我们在景观旋转它减小图像。
所以我尝试下一个解决方案
2.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayoutparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3996db"
android:orientation="vertical"
>
<ScrollView
android:id="@+id/linearlayout_parentscroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearlayout_parents"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_marginTop="@dimen/margin20"
android:layout_gravity="center_horizontal"/>
<RelativeLayout
android:id="@+id/relativelayoutbasic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin20"
android:layout_marginRight="@dimen/margin20"
>
<EditText
android:id="@+id/userName"
android:inputType="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="[email protected]"
android:hint="UserName"
android:drawableStart="@mipmap/ic_launcher"
android:drawablePadding="10dp"
android:background="@null"
android:layout_marginTop="10dp" />
<View
android:id="@+id/view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#f7f7f7"
android:layout_below="@id/userName"
android:layout_marginTop="10dp" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/view"
android:inputType="textPassword"
android:hint="Password"
android:text="[email protected]"
android:drawablePadding="10dp"
android:background="@null"
android:drawableStart="@mipmap/ic_launcher"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/buttonLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/password"
android:background="#f7f7f7"
android:text="Login"
android:textColor="@android:color/black"
android:textAllCaps="false"
android:textStyle="bold"
android:textSize="17sp"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/buttonForgotPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/buttonLogin"
android:layout_marginTop="10dp"
android:text="Forgot Password ?"
android:textColor="@android:color/white"
android:textAllCaps="false"
android:background="@null" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
A中的例子。在此解决方案中,我们无法像使用相对布局一样使用属性android:layout_centerInParent =“true” ,因此我们无法像在解决方案一中那样使登录文本字段居中,该解决方案在小屏幕中看起来不错,有滚动也不能在大屏幕上工作,因为它不会在中心。
B.我们无法在scrollview中使用相对布局,因为它会产生很多其他复杂情况。
我花了这么多时间,使用这么多的堆栈溢出引用和其他人也没有工作。
请提出一些方法来处理它。 在此先感谢...
你的问题是什么? – LightYearsBehind