如何使用LinearLayout增加单选按钮大小
问题描述:
我正在尝试增加RadioButton
的大小LinearLayout
,该大小写入ScrollView
,但它不以任何方式工作。我试图使用像.setScaleX()
和.setScaleY()
这样的属性,但它不起作用。这里是我的代码:如何使用LinearLayout增加单选按钮大小
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" android:weightSum="1">
<LinearLayout
android:paddingTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:orientation="horizontal">
<TextView
android:text="Current location: "
android:textSize="16sp"
android:textStyle="bold"
android:paddingRight="5sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/current_location"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:sca
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/zone_types_list_View"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:orientation="vertical"
android:background="@drawable/room_type_border"/>
</ScrollView>
</LinearLayout>
使用代码来创建单选按钮radioGroup中:
private LinearLayout listView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
listView = (LinearLayout) rootView.findViewById(R.id.zone_types_list_View);
}
private void addRadioButtons() {
if (getActivity() != null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
radioGroup = new RadioGroup(mActivity);
for (String ss : typesList) {
radioButton = new RadioButton(mActivity);
radioButton.setText(ss);
radioButton.setTag(ss.trim());
radioGroup.addView(radioButton);
radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
String tag = (String) buttonView.getTag();
Log.i(TAG, "selected radio: " + tag);
submitZoneType(tag.trim());
}
}
});
}
/* radioGroup.setPivotX(0);
radioGroup.setPivotY(0);
radioGroup.setScaleX(2f);
radioGroup.setScaleY(2f); */
listView.addView(radioGroup);
}
});
}
}
如果我添加radioGroup.setScaleX(2f)
动态,它可以帮助我提高RadioButton
的大小,但其余的buttons
隐藏在layout
和滚动不起作用。我不理解为什么滚动不像这样工作。有没有其他方法可以增加RadioButtons
的大小?
答
试试这个。
在代码中使用radioButton.setLayoutParams(new LinearLayout.LayoutParams(25, 25));
。
LinearLayout linearLayout = (LinearLayout)findViewById(R.id.your_layout);
RadioButton radioButton = new RadioButton(mActivity);
// you can change the width and height
radioButton.setLayoutParams(new LinearLayout.LayoutParams(25, 25));
linearLayout.addView(radioButton);
注意
你可以改变宽度,高度和重量在里面。
view.setLayoutParams(new LinearLayout.LayoutParams(width, height, weight));
你能检查myanswer吗?@ user565 – KeLiuyue