【问题标题】:Linear layout with five textviews and five edittextboxes具有五个文本视图和五个编辑文本框的线性布局
【发布时间】:2011-04-23 16:25:01
【问题描述】:

这里我的布局有问题,我在相对布局中采用了线性布局,我想要五个文本视图,在它们的右边我想添加五个编辑文本框,我做了同样的事情,但布局是每个只显示 3 个,我的意思是三个文本视图和三个编辑文本框,我无法解决,请有人帮忙提供代码

请帮忙,谢谢...!

这是我的代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout android:id="@+id/ll_one" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
    <TextView android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="User Name:"/>
    <EditText android:id="@+id/EditText01"
    android:layout_width="180px"
    android:maxLines="1"

    android:layout_height="wrap_content"/>
</LinearLayout>

<LinearLayout android:id="@+id/ll_two" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@+id/ll_one">
    <TextView android:id="@+id/TextView02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Password:"/>
    <EditText android:id="@+id/EditText02"
    android:layout_width="180px"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dip"
    android:maxLines="1"
    android:password="true"
    android:inputType="textPassword"/>
</LinearLayout>


<LinearLayout android:id="@+id/ll_three" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@+id/ll_two">
    <TextView android:id="@+id/TextView03"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Email:"/>
    <EditText android:id="@+id/EditText03"
    android:layout_width="180px"
    android:layout_height="wrap_content"
    android:layout_marginLeft="42dip"
    android:maxLines="1"
    android:password="true"
    android:inputType="textPassword"/>
   </LinearLayout>

<LinearLayout android:id="@+id/ll_four" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@+id/ll_three">
    <TextView android:id="@+id/TextView04"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="First Name:"/>
    <EditText android:id="@+id/EditText04"
    android:layout_width="180px"
    android:layout_height="wrap_content"
    android:layout_marginLeft="42dip"
    android:password="true"
    android:inputType="textPassword"/>
    </LinearLayout>

<LinearLayout android:id="@+id/ll_three" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentBottom="true">
    <Button 
        android:layout_height="wrap_content" 
        android:text="Sign In"
        android:id="@+id/Button01"
        android:layout_width="fill_parent" 
        android:layout_weight="1"/>
    <Button 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:id="@+id/Button02"
        android:text="New user"
        android:layout_weight="1"/>
 </LinearLayout>
</RelativeLayout>

【问题讨论】:

  • @soorya 我发了,可以吗
  • 在此处发布您的代码,以便我们查看并找到问题
  • @Dharmendra 嗨,我发布了整个 xml 代码,请查看一次
  • 我只看到 1 行代码而不是整个布局。顺便说一句,你最好看看 TableLayout。

标签: android android-layout


【解决方案1】:

我复制了您发布的布局 xml,它看起来符合我的预期。

当然,您的布局 xml 有四行文本视图和编辑视图 - 而不是五行。因此,屏幕截图只有四行这样的行。

这不是你得到的吗?

--

更新

要添加带有另一个文本视图的第五行并编辑文本,您只需将以下内容添加到原始布局 xml 中,就在 ll_four LinearLayout 之后。

    <LinearLayout
        android:id="@+id/ll_five"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/ll_four">
        <TextView
            android:id="@+id/TextView05"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="First Name:" />
        <EditText
            android:id="@+id/EditText05"
            android:layout_width="180px"
            android:layout_height="wrap_content"
            android:layout_marginLeft="42dip"
            android:password="true"
            android:inputType="textPassword" />
    </LinearLayout>

【讨论】:

  • 那你原来的帖子比较混乱。
  • @Raghav 我不知道你的问题是什么。如果我现在正确理解你,你有四行文本视图和编辑文本显示。如果你想要第五个,我猜你知道如何让它出现,因为你得到前四个就好了。如果您只是添加第五个,请参阅我对此答案所做的更新以添加更多 xml。无论如何,如果您澄清您的问题,这可能对您在这里获得帮助是有益的。
  • 国歌非常感谢,我使用表格布局来解决 prblm 现在的工作,但以前我坚持布局,即使我不知道为什么会发生这种情况,因为我是 android 新手。任何人都再次感谢你
【解决方案2】:

您好 Raghav,您能否发布布局代码以便我们分析它。我认为您可以更好地将线性布局嵌入到 ScrollView 中,示例请参考link

希望对你有用。

【讨论】:

  • @Dinash 你好,我发布了代码,你能看一下吗?让我知道代码的问题
  • @Dinash 我发布了总代码,但没有显示,该怎么办
  • @Raghav 浏览此 link to know about table layout 并使用滚动视图布局包装该表格布局
  • 嗨,如果您仍在寻找解决方案,请尝试这段代码 '' 把这个放在你的相对布局中
猜你喜欢
  • 1970-01-01
  • 2016-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多