我已经成功创建了按钮但是现在我希望每个按钮在它下面都有一个单选按钮我做了我应该做的但是仍然没有工作错误就是说找不到属性权重的资源标识符并且这个错误显示在三个单选按钮
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android2="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10" >
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Greetings"
android:textSize="20sp" />
<Button
android:id="@+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="10" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3.3"
android:background="#ff0000"
android:gravity="center"
android:text="@string/red"
android:textColor="#000000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3.4"
android:background="#00ff00"
android:gravity="center"
android:text="@string/green"
android:textColor="#000000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="3.3"
android:background="#0000ff"
android:gravity="center"
android:text="@string/blue"
android:textColor="#000000" />
</LinearLayout>
<RadioGroup
android:id="@+id/myRadioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/myRadioButtonRed"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weight="1" />
<RadioButton
android:id="@+id/myRadioButtonGreen"
style="@style/styleName"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<RadioButton
android:id="@+id/myRadioButtonBlue"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weight="1" />
</RadioGroup>
答案 0 :(得分:0)
用此
替换您的广播组<RadioGroup
android:id="@+id/myRadioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/myRadioButtonRed"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<RadioButton
android:id="@+id/myRadioButtonGreen"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<RadioButton
android:id="@+id/myRadioButtonBlue"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
</RadioGroup>
答案 1 :(得分:0)
你的体重,layout_weight和weightSum有些混乱。 这个固定的代码应该有效:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android2="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="10" >
<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Greetings"
android:textSize="20sp" />
<Button
android:id="@+id/Button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ff0000"
android:gravity="center"
android:text="@string/red"
android:textColor="#000000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#00ff00"
android:gravity="center"
android:text="@string/green"
android:textColor="#000000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#0000ff"
android:gravity="center"
android:text="@string/blue"
android:textColor="#000000" />
</LinearLayout>
<RadioGroup
android:id="@+id/myRadioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" android:weightSum="3">
<RadioButton
android:id="@+id/myRadioButtonRed"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<RadioButton
android:id="@+id/myRadioButtonGreen"
style="@style/styleName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<RadioButton
android:id="@+id/myRadioButtonBlue"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</RadioGroup>
</LinearLayout>