2016-07-16 6 views
-1

У меня есть некоторые проблемы с созданием всплывающего макета с названием TextView, 2 ImageViews, 2 RadioButtons, 2 TextViews для описания изображений и Button распускать всплывающее окно. вот раскладка:Android всплывающего окна макета с радиокнопками

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/myLay" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 


    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/txt1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/img1" 
      android:text="Choose Your Preference:" 
      android:textSize="24sp" 
      android:textStyle="normal|bold" /> 


     <RadioGroup 
      android:id="@+id/myRadioGroup" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checkedButton="@+id/first"> 

      <RadioButton 
       android:id="@+id/first" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

      <RadioButton 
       android:id="@+id/second" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

     </RadioGroup> 

     <ImageView 
      android:id="@+id/img1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/txt2" 
      android:layout_weight="1" 
      android:contentDescription="@string/pre" 
      android:scaleType="centerCrop" 
      android:src="@drawable/optionone" /> 

     <TextView 
      android:id="@+id/txt2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/img2" 
      android:gravity="center_horizontal" 
      android:text="Shrink image and leave borders white." 
      android:textSize="12sp" 
      android:textStyle="normal|bold" /> 

     <ImageView 
      android:id="@+id/img2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_above="@+id/txt3" 
      android:layout_weight="1" 
      android:contentDescription="@string/pre" 
      android:scaleType="centerCrop" 
      android:src="@drawable/optiontwo" /> 

     <TextView 
      android:id="@+id/txt3" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:text="Change image brightness." 
      android:textSize="12sp" 
      android:textStyle="normal|bold" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="Dismiss" 
      android:layout_below="@+id/txt3"/> 
    </LinearLayout> 

</LinearLayout> 

Это выглядит следующим образом:

description

Однако, у меня есть две проблемы, связанные с ним:

1. Я использую android:layout_above:"" внутри LinearLayout , но он работает только таким образом, а не внутри RelativeLayout, а также, если я переключусь на RelativeLayout, я не смогу использовать android:layout_weight=""

2. я не могу получить RadioButton «первый» слева от ImageView «Img1» и RadioButton «второй» слева от ImageView «Img2».

Спасибо.

ответ

1

RadioButton класс распространяется TextView. Поэтому вместо использования отдельного ImageView для каждого из ваших изображений параметров вы можете использовать атрибуты android:drawable для RadioButton, чтобы отобразить изображение, где хотите.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/myLay" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical">  

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/txt1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Choose Your Preference:" 
      android:textSize="24sp" 
      android:textStyle="normal|bold" /> 


     <RadioGroup 
      android:id="@+id/myRadioGroup" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checkedButton="@+id/first"> 

      <RadioButton 
       android:id="@+id/first" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Shrink image and leave borders white." 
       android:textSize="12sp" 
       android:textStyle="normal|bold" 
       android:drawableBottom="@drawable/optionone" /> 

      <RadioButton 
       android:id="@+id/second" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Change image brightness." 
       android:textSize="12sp" 
       android:textStyle="normal|bold" 
       android:drawableBottom="@drawable/optiontwo" /> 

     </RadioGroup> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:text="Dismiss" /> 
    </LinearLayout> 

</LinearLayout> 
+0

А как насчет использования android: layout_above = "" внутри LinearLayout? – DAVIDBALAS1

+0

Вы правы. При попытке помочь вам я сделал ошибку при копировании, вставке и исправлении исходного макета xml, не удалив строку 'layout_above ='. Прошу прощения. Пожалуйста, прости меня. Я удалил оскорбительную строку * ВАШ * код –

+0

Это прекрасно, я просто подумал, что у вас есть ошибка, извините bro :( – DAVIDBALAS1

Смежные вопросы