【问题标题】:One half - ImageView must occupy 50% & the other half - 2 EditTexts & 2 Buttons must occupy other 50%一半 - ImageView 必须占 50%,另一半 - 2 个 EditTexts 和 2 个 Button 必须占其他 50%
【发布时间】:2023-04-04 10:03:01
【问题描述】:

我需要形成一个布局,我想在屏幕的上 50% 中放置一个图像,在屏幕的下 50% 中放置两个 EditText 和两个按钮,并且它应该与设备无关,以便视图在更小或更大的屏幕上不会受到干扰,它在最小 3.2 英寸 HVGA 设备上运行良好,但如果在更小的设备上运行,一切都会重叠。添加 ScrollView 后,它不会为您提供所需的输出,这是我的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_gravity="center"
    android:layout_weight="0.5"
    android:gravity="center"
    android:scaleType="center"
    android:src="@drawable/ic_launcher" />

<EditText
    android:id="@+id/email"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.125"
    android:ems="10"
    android:inputType="textEmailAddress" >
</EditText>

<EditText
    android:id="@+id/password"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.125"
    android:ems="10"
    android:inputType="textPassword" />

<Button
    android:id="@+id/submit"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.125"
    android:text="Sign In" />

<Button
    android:id="@+id/signup"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.125"
    android:text="Create An Account" />

</LinearLayout>

【问题讨论】:

  • 你没有 textviews 但 edittexts...
  • @Zoran 废话,我的错。已编辑。

标签: java android android-layout android-linearlayout android-imageview


【解决方案1】:

这是你的布局需要的样子,伪代码:

<Linearlayout - vertical
    <ImageView, weight 1 />
    <LinearLayout - horizontal, weight 1 
        <LinearLayout - vertical, weight 1
            <TextView, weight 1 />
            <Button, weight 1 />
        <LinearLayout - vertical, weight 1
            <TextView, weight 1 />
            <Button, weight 1 />
    />
/>

对于TextViewsButtons,确保将宽度设置为match_parent。对于ImageViewLinearLayout,确保将高度和宽度设置为0dp

【讨论】:

  • 我什至还有按钮,那些呢?
  • @DerGolem 那在添加 ScrollView 之后还是没有呢?
  • 文本视图下方的按钮?
  • @RiteshPanjwani ... 哪个 ScrollView?
猜你喜欢
  • 2021-08-14
  • 1970-01-01
  • 1970-01-01
  • 2021-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-03
  • 1970-01-01
相关资源
最近更新 更多