Java 在同一直线上设置文本框

Java 在同一直线上设置文本框,java,android,user-interface,textbox,Java,Android,User Interface,Textbox,请看一下下面的代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertica

请看一下下面的代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
     >

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/firstNumber"
        />

    <EditText 
        android:id="@+id/firstNumberTxt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        />

    </LinearLayout>

     <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/secondNumber"
        />

    <EditText 
        android:id="@+id/secondNumberTxt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        />

    </LinearLayout>



         <RadioGroup
             android:id="@+id/radioGroup"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:orientation="horizontal"
             >

             <RadioButton 
                 android:id="@+id/sum"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/sum"
                 />

             <RadioButton 
                 android:id="@+id/min"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/min"
                 />

             <RadioButton 
                 android:id="@+id/max"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/max"
                 />

             <RadioButton 
                 android:id="@+id/dev"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:text="@string/dev"
                 />
         </RadioGroup>

</LinearLayout>

此代码的输出GUI作为图像附加


但是,您可以看到一个文本框在另一个文本框之前启动,这使得GUI很难看。我需要在同一列中以一条直线显示文本框。例如,如果文本框1从X=1和Y=1开始,那么第二个文本框应该从X=1和Y=2开始,这个例子是Java的例子。请帮忙

对文本视图使用固定大小(例如,两种视图都使用
android:layout\u width=“20dip”
)。或者用于显示两列:第一列将存储TextView,第二列将包含EditText

让我试试

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
 >

<TextView 
    android:id="@+id/firstTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/firstNumber"
    android:alignParentLeft="true"
    android:alignParentTop="true"
    />

<EditText 
    android:id="@+id/firstNumberTxt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:toRightOf="@+id/firstTextView"
    android:marginLeft=30dp 
    />

<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/secondNumber"
    android:alignLeft="@+id/firstTextView"
    android:below="@+id/firstTextView"
    />

<EditText 
    android:id="@+id/secondNumberTxt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:alignLeft="@+id/firstNumberTxt"
    android:below="@+id/firstTextView"
    />

     <RadioGroup
         android:id="@+id/radioGroup"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:orientation="horizontal"
         >

         <RadioButton 
             android:id="@+id/sum"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/sum"
             />

         <RadioButton 
             android:id="@+id/min"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/min"
             />

         <RadioButton 
             android:id="@+id/max"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/max"
             />

         <RadioButton 
             android:id="@+id/dev"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/dev"
             />
     </RadioGroup>


使用相对布局并在左侧对齐。。。。我现在就给你写点东西。相信我,如果可以的话,你真的想避免使用除了相对布局以外的所有布局……谢谢你的回复,但是你的android版本是什么?我使用的是2.2,我看不到那些对齐xml代码@克辛奇:是的,我是。你的代码不能很好地适应不同的分辨率和不同的字体大小,我的代码忽略了这个问题。Sepala,相对布局从API级别1开始就存在。检查编辑。大问题!他们不在我的范围内!!怎么了+1不管怎样,我@Shark的大多数属性都缺少
layout\uu
前缀。在这种情况下,我强烈推荐RelativeLayout,所以我投了赞成票@Kzinch具有给定dp值的解决方案无法按照定义很好地缩放。两种解决方案各有利弊,但固定的dp和不需要的表格布局。为什么RU使用“dip”而不是“dp”?我看过“0dp”和那些东西,这是我第一次看到“dip”的尺寸调整。它们是不同的吗?它们只是完全相同的东西-独立于维度的像素。啊..太好了..谢谢你的帮助!请记住,当您以后决定扩展应用程序并希望将其移植到不同的分辨率/设备时,这个表会让您非常痛苦,以至于您将重写gui XML,而不是从中删除这些表。有了最后期限和众多其他(android)bug,你可能不想在这上面浪费时间。将表格留给HTML设计师,当您想将某个内容与其他内容放在同一位置时,请使用RelativeLayout。这是一个真实的生产故事。提前考虑:)
  android:layout_below="@+id/listActiveChat"
  android:layout_toRightOf="@+id/mesagge_edit"