[英]Issue with layout alignment
I have a relative layout with two linear layout inside it with two textviews in each of them. 我有一个相对的布局,其中有两个线性布局,每个布局中都有两个textview。 I wanted the textviews to appear horizontally as a row. 我希望textviews水平显示为一行。 The code is given below: 代码如下:
<RelativeLayout
android:id="@+id/linear2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/txtlinear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/esms_parentfees_classtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/esms_parentfees_classdetais"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/esms_parentfees_classdetais"
android:orientation="horizontal" >
<TextView
android:id="@+id/esms_parentfees_datetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/esms_parentfees_datedetais"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
Notes on your XML: 关于XML的注释:
This is needed for some reason to show all the XML? 由于某种原因需要显示所有XML吗? Ignore this line 忽略这条线
<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/esms_parentfees_classtext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<TextView
android:id="@+id/esms_parentfees_classdetais"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/esms_parentfees_datetext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<TextView
android:id="@+id/esms_parentfees_datedetais"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
</LinearLayout>
</RelativeLayout>
The easiest way would be to make the outer RelativeLayout a LinearLayout 最简单的方法是使外部RelativeLayout为LinearLayout
<LinearLayout
android:id="@+id/linear2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
Then remove any tag like 然后删除任何标签,例如
android:layout_toRightOf="@+id/esms_parentfees_classdetais"
Or, you could just change the tag mentioned above to 或者,您可以将上面提到的标签更改为
android:layout_below="@+id/esms_parentfees_classdetais"
if you need the four textviews in a row its easy to just use a linear layout with the four text views in it (or a table layout) instead of using two linear layouts in a relative layout. 如果您需要连续四个文本视图,则只需在其中使用四个文本视图的线性布局(或表格布局),而不是在相对布局中使用两个线性布局,这很容易。
Have a look at this : 看看这个:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/txtlinear"
>
<TextView
android:id="@+id/esms_parentfees_classtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="@+id/esms_parentfees_classdetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="@+id/esms_parentfees_datetext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="@+id/esms_parentfees_datedetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
</LinearLayout>
or 要么
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/txtlinear"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/esms_parentfees_classtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="@+id/esms_parentfees_classdetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="@+id/esms_parentfees_datetext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="@+id/esms_parentfees_datedetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
</TableRow>
</TableLayout>
or if its a compulsion that you need a relative layout with two linear layouts in it you can follow any of the solutions above 或者如果您需要其中包含两个线性布局的相对布局,则可以遵循上述任何解决方案
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/esms_parentfees_classtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/esms_parentfees_classdetais"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/esms_parentfees_classtext"
/>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.