Android 使放射组与match_parent水平均匀延伸
我遇到的问题是,我似乎无法让它与你的父母正确匹配。我想要它做的是延伸到页面的末尾,如下图所示。 我已经尝试了几乎所有的方法,但我提出的唯一解决方案是添加一个固定的px,这是我不想做的,因为它在不同的平台上冲突Android 使放射组与match_parent水平均匀延伸,android,android-layout,android-studio,Android,Android Layout,Android Studio,我遇到的问题是,我似乎无法让它与你的父母正确匹配。我想要它做的是延伸到页面的末尾,如下图所示。 我已经尝试了几乎所有的方法,但我提出的唯一解决方案是添加一个固定的px,这是我不想做的,因为它在不同的平台上冲突 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="net.battleplugins.msutton.fragemento.MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/menu_row">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="75dp"
android:orientation='horizontal'>
<RadioButton
android:text="@string/quiz_button_title"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/quiz_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
<RadioButton
android:text="@string/picture_button_title"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/picture_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
<RadioButton
android:text="@string/events_button_title"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/events_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
</RadioGroup>
</TableRow>
</TableLayout>
</RelativeLayout>
我得到的是:
我想让它做的是:
问题是这是一个固定的数额。
android:layout_width=“1075px”在RadioGroup中,您可以改用LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="horizontal"
tools:context="net.battleplugins.msutton.fragemento.MainActivity">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="75dp"
android:orientation='horizontal'>
<RadioButton
android:text="@string/quiz_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/quiz_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
<RadioButton
android:text="@string/picture_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/picture_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
<RadioButton
android:text="@string/events_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/events_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
</RadioGroup>
</LinearLayout>
您可以改用线性布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="horizontal"
tools:context="net.battleplugins.msutton.fragemento.MainActivity">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="75dp"
android:orientation='horizontal'>
<RadioButton
android:text="@string/quiz_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/quiz_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
<RadioButton
android:text="@string/picture_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/picture_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
<RadioButton
android:text="@string/events_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/events_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
</RadioGroup>
</LinearLayout>
线性布局是实现这一目标的最佳方法
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="net.battleplugins.msutton.fragemento.MainActivity">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="75dp"
android:orientation='horizontal'>
<RadioButton
android:text="@string/quiz_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/quiz_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
<RadioButton
android:text="@string/picture_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/picture_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
<RadioButton
android:text="@string/events_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/events_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
</RadioGroup>
</LinearLayout>
线性布局是实现这一目标的最佳方法
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="net.battleplugins.msutton.fragemento.MainActivity">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="75dp"
android:orientation='horizontal'>
<RadioButton
android:text="@string/quiz_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/quiz_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
<RadioButton
android:text="@string/picture_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/picture_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
<RadioButton
android:text="@string/events_button_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/events_button"
android:button="@android:color/transparent"
android:background="@drawable/buttonbackground"
android:layout_weight="1"
android:onClick="updateFragment"/>
</RadioGroup>
</LinearLayout>
如果要使用表格布局
,请在表格布局
中指定android:stretchColumns=“1”
,在放射组
中指定android:stretchColumns=“1”
如果要使用表格布局
,请指定android:stretchColumns=“1”
在您的表格布局中
和android:layout\u column=“1”
在您的放射组中
使用权重,而不是设置绝对宽度
<RadioGroup
android:weightSum="3"
android:layout_width="match_parent"
android:layout_height="75dp"
android:orientation='horizontal'>
<RadioButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</RadioGroup>
使用重量,而不是设置绝对宽度
<RadioGroup
android:weightSum="3"
android:layout_width="match_parent"
android:layout_height="75dp"
android:orientation='horizontal'>
<RadioButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<RadioButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
</RadioGroup>
你可能是上帝。非常感谢你,你可能是上帝。非常感谢你。