我的应用程序上有登录屏幕的基本布局 . 我想在屏幕顶部对齐徽标 . 电子邮件和密码字段,以及屏幕中间的登录按钮 . 比两个按钮在屏幕底部创建帐户和忘记密码(堆叠在彼此的顶部) . 我无法弄清楚我的生活怎么做 . 我试图使用“aligninParent”属性,它确实有效,但当我改变手机方向时,它会导致字段重叠 . 我是否需要为景观创建不同的布局?
我的代码:
<?xml version="1.0" encoding="utf-8"?><!-- Login Form -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="@drawable/radialback">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp">
<!-- Logo -->
<ImageView
android:id="@+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginBottom="25dp"
android:contentDescription="@string/se_logo"
android:scaleType="fitCenter"
android:src="@drawable/se_logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical">
<!-- Email Address -->
<EditText
android:id="@+id/login_email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:layout_marginBottom="15dp"
android:hint="@string/email"
android:textColorHint="@color/blue"
android:singleLine="true"
android:background="@drawable/blue_edit_text">
<requestFocus />
</EditText>
<!-- Password -->
<EditText
android:id="@+id/login_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_marginBottom="10dp"
android:hint="@string/pw"
android:textColorHint="@color/blue"
android:password="true"
android:singleLine="true"
android:background="@drawable/blue_edit_text" />
<!-- Login Button -->
<Button
android:id="@+id/btnLogin"
android:layout_width="210dp"
android:layout_height="35dp"
android:layout_marginTop="15dp"
android:background="@drawable/btn_style"
android:layout_gravity="center"
android:text="@string/login"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="bottom">
<!-- Link to Register -->
<Button
android:id="@+id/btnlink_to_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dip"
android:layout_marginBottom="5dp"
android:text="@string/create_account"
android:textColor="@color/text_color"
android:background="@null"
android:textSize="15sp" />
<!-- Forgot Password Button -->
<Button
android:id="@+id/btnlink_forgot_password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/forgot_password"
android:textColor="@color/text_color"
android:background="@null"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
2 回答
不要使用fill_parent,替换match_parent(前者已弃用) .
简短回答:是的,如果您希望它的外观不同,则需要不同的横向布局 .
你似乎使用了太多的布局 .
徽标不应位于线性布局内,您可以对该图像视图使用AlignParentTop = true .
下一个LinearLayout(对于电子邮件/用户等)应该是“alignBelow =
如果使用相对布局,则为视图/小部件添加ID,因为这是您在屏幕中定位它们的方式 .
仅使用LinearLayouts将单个视图组放在一个可以作为整体适应的块中 .
阅读一些布局权重,让您的一个视图相应地使用剩余的“未使用”空间 .
和帖子你想要的截图:)
试试这个..