2017-09-20 77 views
0

我正在嘗試增加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的大小?

+0

你能檢查myanswer嗎?@ user565 – KeLiuyue

回答

0

其任職

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

那麼ScrollView不會垂直滾動什麼單選按鈕的大小增加。所以其餘的單選按鈕隱藏在視圖 – user565

+0

你設置滾動視圖內** android:layout_width =「match_parent」 android:layout_height =「fill_parent」** –

+0

仍然沒有運氣與此 – user565

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));