[英]How to set the weight in the Relative Layout
I am creating a box that will show some data in that.I want to set the positions of the textview so that if the text size increase it can be handled easliy. 我正在创建一个显示一些数据的框。我想设置textview的位置,这样如果文本大小增加,就可以轻松处理。
I have created this layout but the issue is if the text size i am getting larger from the server then it is getting messed up with each other how could we handle this. 我已经创建了这个布局,但问题是如果文本大小我从服务器变得越来越大,那么彼此搞砸了我们怎么能处理这个问题。
XML XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:background="@layout/rectangle_shape" >
<TextView
android:id="@+id/approvalId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="ApprovalId :"
android:textStyle="bold" />
<TextView
android:id="@+id/approvalId_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/approvalId"
android:text="Co07039645" />
<TextView
android:id="@+id/admin_remarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/approvalId"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="AdminRemarks :"
android:textStyle="bold" />
<TextView
android:id="@+id/admin_remarks_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/admin_remarks"
android:layout_below="@+id/approvalId_value"
android:text="Test Remarks Done by Pooja who is the admin of the employee" />
<TextView
android:id="@+id/current_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/admin_remarks"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="Current Status :"
android:textStyle="bold" />
<TextView
android:id="@+id/current_status_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/current_status"
android:layout_below="@+id/admin_remarks_value"
android:text="Approved" />
<TextView
android:id="@+id/update_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/current_status"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="Update Time :"
android:textStyle="bold" />
<TextView
android:id="@+id/update_time_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/update_time"
android:layout_below="@+id/current_status_value"
android:text="2014-03-07 13:42:18" />
<TextView
android:id="@+id/previous_costcenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/update_time"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="Previous Costcenter :"
android:textStyle="bold" />
<TextView
android:id="@+id/previous_costcenter_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/previous_costcenter"
android:layout_below="@+id/update_time_value"
android:text="All" />
<TextView
android:id="@+id/current_costcenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/previous_costcenter"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:text="Previous Costcenter :"
android:textStyle="bold" />
<TextView
android:id="@+id/current_costcenter_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="@+id/current_costcenter"
android:layout_below="@+id/previous_costcenter_value"
android:text="All" />
</RelativeLayout>
</RelativeLayout>
Remarks will have the maximum length of data rest will similar as i have posted in the XML 备注将具有与我在XML中发布的数据相同的最大数据长度
Here according to your question you can't use Weight for Relativelayout. 根据您的问题,您不能使用Weight for Relativelayout。 If you want to use then you can use Linear Layout with horizontal or vertical orientation. 如果要使用,则可以使用水平或垂直方向的线性布局。 So answer from your question, 所以回答你的问题,
<?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" >
<LinearLayout
android:id="@+id/result"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="2dp"
android:layout_marginTop="5dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/approvalId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="ApprovalId :"
android:textStyle="bold" />
<TextView
android:id="@+id/approvalId_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="Co07039645" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/admin_remarks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:maxLines="5"
android:text="Admin Remarks :"
android:textStyle="bold" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" >
<TextView
android:id="@+id/admin_remarks_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Test Remarks Done by Pooja who is the admin of the employee" />
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/current_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="Current Status :"
android:textStyle="bold" />
<TextView
android:id="@+id/current_status_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="Approved" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/update_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="Update Time :"
android:textStyle="bold" />
<TextView
android:id="@+id/update_time_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="2014-03-07 13:42:18" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/previous_costcenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="Previous Costcenter :"
android:textStyle="bold" />
<TextView
android:id="@+id/previous_costcenter_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="All" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/current_costcenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="Previous Costcenter :"
android:textStyle="bold" />
<TextView
android:id="@+id/current_costcenter_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="All" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You can't set weight
in RelativeLayout
. 您无法在RelativeLayout
设置weight
。 If you want to maintain your layout with weight
then you should use `Linearlayout. 如果你想保持你的布局与weight
那么你应该使用`Linearlayout。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.