2012-03-24 27 views
7

Tôi đang cố gắng để có được một số vị trí hợp lý của radio của tôi là một phần của RadioGroup. Tôi đã gặp rắc rối khi RadioGroup của tôi đang ngồi trên phần còn lại của thiết kế bố cục, sau đó tôi sử dụng lề để đẩy các nút xung quanh, vấn đề ở đây là chỉ hoạt động trên một hoặc hai bố cục thiết bị. Tôi nghĩ rằng tôi đánh vàng khi tôi phát hiện ra tôi có thể xác định RadioGroup của tôi sau đó đặt trong một RelativeLayout dưới đây mà trong số những thứ khác có một trong những RadioButtons, sau đó tôi lặp lại hai lần nữa. điều này mang lại cho tôi bố cục tôi mong muốn. Vấn đề là, khi tôi chạy mã, RadioButtons hành động nút độc lập liên kết :(Android: RadioButton trong Bố cục lồng nhau trong RadioGroup rơi ra khỏi nhóm

Vì vậy, hai câu hỏi,

  • tôi có thể liên kết các nút trở lại cho Tập đoàn?

  • Có phong nha để có thể xác định bố trí của RadioGroup Radiobuttons độc lập với Tập đoàn

Tôi nghĩ một sự thay thế có thể là RadioButton độc lập và sử dụng mã để bật/tắt chúng, nhưng điều đó có thể đánh bại tính hữu dụng của RadioGroup.

cảm ơn.

Đây là bố cục XML của tôi nếu bạn tò mò.

<ScrollView android:id="@+id/scrollview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 

     android:layout_below="@id/HDDResultsBox" 
     > 

    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:windowSoftInputMode="stateHidden" 
    > 


    <RadioGroup android:id="@+id/calcBy" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:focusable="true" 
     android:focusableInTouchMode="true" 
     android:layout_below="@id/HDDResultsBox" 

     > 

    <RelativeLayout android:id="@+id/intervalBox" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/backgroundbox" 
     android:layout_margin="5dp" 
     android:padding="5dp" 


     > 
      <TextView android:id="@+id/intervalHeader" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Interval" 
      android:gravity="left" 
      android:textColor="#ffffff" 
      android:textStyle="bold" 
      android:layout_marginLeft="5dp" 
      />  

     <TextView android:id="@+id/intervalHelpText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Interval help text" 
      android:gravity="left" 
      android:textColor="#ffffff" 
      android:textSize="8dp" 
      android:layout_toRightOf="@id/intervalHeader" 
      android:layout_marginLeft="10dp" 
      /> 

      <LinearLayout android:id="@+id/interval2ndBox" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_below="@id/intervalHeader" 
      android:layout_marginLeft="10dp" 
      > 
       <RadioButton android:id="@+id/byInterval" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="2dp" 
        /> 

       <EditText android:id="@+id/intervalValue" 
        android:layout_width="75dp" 
        android:layout_height="40dp" 
        android:text="50" 
        android:textSize="14sp" 
        android:gravity="center" 
        android:inputType="number" 
        android:layout_marginLeft="20dp" 
        />  

       <Spinner android:id="@+id/intervalType" 
        android:layout_width="match_parent" 
        android:layout_height="42dp" 
        android:drawSelectorOnTop="false" 
        android:layout_marginTop="1dp" 
        android:layout_marginLeft="10dp" 
        android:layout_weight="10" 
       android:layout_marginRight="2dp" 
        /> 

       <SeekBar android:id="@+id/intervalSeek" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:max="100" 
       android:progress="50" 
       android:layout_marginLeft="5dp" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="8dp" 
       android:layout_weight="7" 
      /> 
      </LinearLayout> 

     </RelativeLayout> 


<RelativeLayout android:id="@+id/recordBox" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/backgroundbox" 
     android:layout_margin="5dp" 
     android:padding="5dp" 


     > 
      <TextView android:id="@+id/recordHeader" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Record Duration" 
      android:gravity="left" 
      android:textColor="#ffffff" 
      android:textStyle="bold" 
      android:layout_marginLeft="5dp" 
      />  

     <TextView android:id="@+id/recordHelpText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Record help text" 
      android:gravity="left" 
      android:textColor="#ffffff" 
      android:textSize="8dp" 
      android:layout_toRightOf="@id/recordHeader" 
      android:layout_marginLeft="10dp" 
      /> 

      <LinearLayout android:id="@+id/record2ndBox" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_below="@id/recordHeader" 
      android:layout_marginLeft="10dp" 
      > 
       <RadioButton android:id="@+id/byrecord" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="2dp" 
        /> 

       <EditText android:id="@+id/recordValue" 
        android:layout_width="75dp" 
        android:layout_height="40dp" 
        android:text="50" 
        android:textSize="14sp" 
        android:gravity="center" 
        android:inputType="number" 
        android:layout_marginLeft="20dp" 
        />  

       <Spinner android:id="@+id/recordType" 
        android:layout_width="match_parent" 
        android:layout_height="42dp" 
        android:drawSelectorOnTop="false" 
        android:layout_marginTop="1dp" 
        android:layout_marginLeft="10dp" 
        android:layout_weight="10" 
       android:layout_marginRight="2dp" 
        /> 

       <SeekBar android:id="@+id/recordSeek" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:max="100" 
       android:progress="50" 
       android:layout_marginLeft="5dp" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="8dp" 
       android:layout_weight="7" 
      /> 
      </LinearLayout> 

     </RelativeLayout> 

<RelativeLayout android:id="@+id/playBackBox" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/backgroundbox" 
     android:layout_margin="5dp" 
     android:padding="5dp" 


     > 
      <TextView android:id="@+id/playBackHeader" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Video Length" 
      android:gravity="left" 
      android:textColor="#ffffff" 
      android:textStyle="bold" 
      android:layout_marginLeft="5dp" 
      />  

     <TextView android:id="@+id/playBackHelpText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="playBack help text" 
      android:gravity="left" 
      android:textColor="#ffffff" 
      android:textSize="8dp" 
      android:layout_toRightOf="@id/playBackHeader" 
      android:layout_marginLeft="10dp" 
      /> 

      <LinearLayout android:id="@+id/playBack2ndBox" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_below="@id/playBackHeader" 
      android:layout_marginLeft="10dp" 
      > 
       <RadioButton android:id="@+id/byplayBack" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="2dp" 
        /> 

       <EditText android:id="@+id/playBackValue" 
        android:layout_width="75dp" 
        android:layout_height="40dp" 
        android:text="50" 
        android:textSize="14sp" 
        android:gravity="center" 
        android:inputType="number" 
        android:layout_marginLeft="20dp" 
        />  

       <Spinner android:id="@+id/playBackType" 
        android:layout_width="match_parent" 
        android:layout_height="42dp" 
        android:drawSelectorOnTop="false" 
        android:layout_marginTop="1dp" 
        android:layout_marginLeft="10dp" 
        android:layout_weight="10" 
       android:layout_marginRight="2dp" 
        /> 

       <SeekBar android:id="@+id/playBackSeek" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:max="100" 
       android:progress="50" 
       android:layout_marginLeft="5dp" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="8dp" 
       android:layout_weight="7" 
      /> 
      </LinearLayout> 

     </RelativeLayout>  


    </RadioGroup>   
</RelativeLayout> 
     </ScrollView> 
+0

loại bỏ nhóm radiogroup và tự xử lý các nút nếu nó không hoạt động với radiogroup. Giống như nút bấm button1: đặt tất cả những người khác thành không hoạt động. – zapl

+0

Tôi thất vọng vì bạn không thể kiểm soát nhóm tốt hơn, nhưng bây giờ tôi đã điều chỉnh mã của mình để sử dụng các nút theo cách thủ công. cổ vũ. – Purplemonkey

Trả lời

7

Sau khi tìm kiếm giải pháp, cách duy nhất để thực hiện việc này là sử dụng các nút radio riêng lẻ và sau đó điều khiển chương trình ở trạng thái bật/tắt.

+1

Bạn nghĩ Google sẽ đưa ra giải pháp cho điều này. Tôi gặp phải điều này khi tạo nút "Khác". Đặt một TextEdit trong sau nút đã được chứng minh là rất khó khăn ... –

Các vấn đề liên quan