问题描述
我正在开发一个反馈应用程序,该应用程序应具有与此屏幕相似的布局. [1]: https://i.stack.imgur.com/xn3kh.jpg
I am developing a feedback application which should has similar layout to this screen. [1]: https://i.stack.imgur.com/xn3kh.jpg
我已经为布局设计了xml.
I have designed the xml for layout.
<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:background="#000"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.zankrutparmar.feedback.Frag_one">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/frag_one_title"
android:textColor="#fff"
android:textStyle="bold|italic"
android:textSize="35dp"
android:textAlignment="center"/>
<LinearLayout
android:layout_width="819dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginEnd="@dimen/activity_vertical_margin"
android:text="Poor"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_vertical_margin"
android:text="Average"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_vertical_margin"
android:text="Good"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_vertical_margin"
android:text="Very Good"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_vertical_margin"
android:text="Excellent"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="35dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="6">
<TextView
android:layout_width="58dp"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_vertical_margin"
android:layout_weight="1"
android:text="Theme & Decor"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="25dp"
android:textStyle="bold|italic" />
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/activity_vertical_margin"
android:layout_weight="5"
android:orientation="horizontal">
<RadioButton
android:id="@+id/poor1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/custom_btn_radio_poor"
android:button="@null" />
<RadioButton
android:id="@+id/average1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/custom_btn_radio_average"
android:button="@null" />
<RadioButton
android:id="@+id/good1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/custom_btn_radio_good"
android:button="@null" />
<RadioButton
android:id="@+id/very1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/custom_btn_radio_very_good"
android:button="@null" />
<RadioButton
android:id="@+id/excellent1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/custom_btn_radio_excellent"
android:button="@null" />
</RadioGroup>
</LinearLayout>
现在,每当我要对这些单选按钮应用边距时,中间的一个将保持居中,并将所有其他按钮推远.
Now whenever I want to apply margin to these radio buttons the center one remains in center and pushes all other buttons far.
我还尝试了有关此问题[1]的答案:在android中对齐了标签的无线电组的TableLayout
I also tried the answers on this question [1]: TableLayout of radiogroup(s) with respective label(s) aligned in android
但是在这种布局中,问题在于单行中的所有按钮都被选中了.这意味着不能将Radiogroup放置在该布局中.
But in that layout the problem is all buttons in single row are getting selected. It means Radiogroup can't be placed in that layout.
我必须从数据库中获取问题并将其放入我的应用程序中.因此,将来我将不得不动态添加行.任何帮助将不胜感激.预先谢谢你.
And I have to fetch questions from a database and place them in my application.So in Future I will have to add rows dynamically.Any help will be very appreciated. Thank you in advance.
推荐答案
好的,我设计了一个新的布局并修复了以前的问题.我正在上传该代码.
Okay I designed a new layout and fixed those previous issues. I am uploading that code.
<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:background="#8bae3a"
tools:context="com.zankrutparmar.feedback.Frag_two">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_marginLeft="20dp"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView5"
android:layout_column="1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView10"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView9"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView6"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
</TableRow>
<TableRow
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<RadioGroup
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:orientation="horizontal">
<RadioButton
style="@style/MyRadioButtonStyle"
android:gravity="center"
android:padding="8dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
style="@style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
/>
<RadioButton
style="@style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="7dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</RadioGroup>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<RadioGroup
android:layout_marginLeft="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:orientation="horizontal">
<RadioButton
style="@style/MyRadioButtonStyle"
android:gravity="center"
android:padding="8dp"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
style="@style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="5dp"
/>
<RadioButton
style="@style/MyRadioButtonStyle"
android:gravity="center"
android:paddingLeft="8dp"
android:layout_marginLeft="7dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
</RadioGroup>
</TableRow>
</TableLayout>
这篇关于表布局中的单选组,单选按钮与列对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!