如何使用LinearLayout增加单选按钮大小

时间:2017-09-20 09:54:16

标签: android android-layout android-radiogroup

我正在尝试增加controls.target controls.cameraTarget的大小,其中包含RadioButton,但它无论如何都无法正常工作。我尝试使用LinearLayoutScrollView这样的属性,但它没有用。这是我的代码:

layout.xml:

.setScaleX()

使用radioGroup创建单选按钮的代码:

.setScaleY()

如果我动态添加<?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> ,则可以帮助我增加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的大小?

2 个答案:

答案 0 :(得分:0)

其工作

radioButton.setHeight(10);
radioButton.setWidth(5);

答案 1 :(得分:0)

试试这个。

在代码中使用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));