Android 如何在相对布局中水平设置两个文本视图的相等大小
这是我的xml,我想在相对布局中设置两个文本视图,等分水平,但使用此xml左文本视图只占很少的部分,而右文本视图占用很大的空间。请告诉我我做错了什么。尝试一下,您可以使用Android 如何在相对布局中水平设置两个文本视图的相等大小,android,Android,这是我的xml,我想在相对布局中设置两个文本视图,等分水平,但使用此xml左文本视图只占很少的部分,而右文本视图占用很大的空间。请告诉我我做错了什么。尝试一下,您可以使用线性布局将两个文本视图设置为相同的权重TextView类似下面的代码 <RelativeLayout android:id="@+id/footer" android:layout_width="match_parent" android:layo
线性布局
将两个文本视图设置为相同的权重TextView
类似下面的代码
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#b4d3d3">
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#5d737e"
android:padding="20dp"
android:text="First" />
<TextView
android:id="@+id/world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/hello"
android:padding="20dp"
android:text="Second" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#b4d3d3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#5d737e"
android:padding="20dp"
android:layout_weight="1"
android:text="First" />
<TextView
android:id="@+id/world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/hello"
android:padding="20dp"
android:layout_weight="1"
android:text="Second" />
</LinearLayout>
</RelativeLayout>
尝试一下,您可以使用LinearLayout
将两个TextView
设置为相同的Weight
,如下代码所示
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#b4d3d3">
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#5d737e"
android:padding="20dp"
android:text="First" />
<TextView
android:id="@+id/world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/hello"
android:padding="20dp"
android:text="Second" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#b4d3d3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#5d737e"
android:padding="20dp"
android:layout_weight="1"
android:text="First" />
<TextView
android:id="@+id/world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/hello"
android:padding="20dp"
android:layout_weight="1"
android:text="Second" />
</LinearLayout>
</RelativeLayout>
尝试下面的代码
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#b4d3d3">
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#5d737e"
android:padding="20dp"
android:text="First" />
<TextView
android:id="@+id/world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/hello"
android:padding="20dp"
android:text="Second" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#b4d3d3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#5d737e"
android:padding="20dp"
android:layout_weight="1"
android:text="First" />
<TextView
android:id="@+id/world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/hello"
android:padding="20dp"
android:layout_weight="1"
android:text="Second" />
</LinearLayout>
</RelativeLayout>
尝试下面的代码
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#b4d3d3">
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#5d737e"
android:padding="20dp"
android:text="First" />
<TextView
android:id="@+id/world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/hello"
android:padding="20dp"
android:text="Second" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#b4d3d3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#5d737e"
android:padding="20dp"
android:layout_weight="1"
android:text="First" />
<TextView
android:id="@+id/world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/hello"
android:padding="20dp"
android:layout_weight="1"
android:text="Second" />
</LinearLayout>
</RelativeLayout>
使用完美重量概念
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#b4d3d3"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_weight="1"
android:id="@+id/hello"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#5d737e"
android:padding="20dp"
android:text="First" />
<TextView
android:layout_weight="1"
android:id="@+id/world"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/hello"
android:padding="20dp"
android:text="Second" />
</LinearLayout>
</RelativeLayout>
使用完美重量概念
<RelativeLayout
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#b4d3d3"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_weight="1"
android:id="@+id/hello"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#5d737e"
android:padding="20dp"
android:text="First" />
<TextView
android:layout_weight="1"
android:id="@+id/world"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/hello"
android:padding="20dp"
android:text="Second" />
</LinearLayout>
</RelativeLayout>
使用权重…但我使用的是相对布局,我想在MinnuKaAnae使用相对布局使用权重…但我使用的是相对布局,我想在MinnuKaAnae使用相对布局