2015-06-09 5 views
-1

Я использую макет для отображения диалога. В моей конструкции XML является совершенным, но когда я открыть его в приложение, оно зашифровано .. Ниже приведены снимки экрана:Диалог Android сжимается

Конструкция XML-файл:

xml

И диалог в мобильном телефоне :

mobile

мой XML-код:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:weightSum="11" 
android:background="#ffffff"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" > 

    <TextView 
     android:id="@+id/textView_goal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:text="Set You Goal with " 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

</RelativeLayout> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="4" > 
    </RelativeLayout> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal" 
    android:weightSum="2" > 

    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_weight="1.5" 
     android:layout_height="match_parent" > 

     <EditText 
       android:id="@+id/goal_value_1" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:ems="10" 
       android:layout_marginLeft="40dp" 
       android:inputType="phone" > 

      <requestFocus /> 
     </EditText> 

    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_weight="0.5" 
     android:layout_height="match_parent" > 

     <TextView 
      android:id="@+id/goal_unit_1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:text="mm Hg" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
    /> 

    </RelativeLayout> 

    </LinearLayout> 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.5" 
    android:orientation="horizontal" 
    android:weightSum="2" > 
    </LinearLayout> 
    <LinearLayout 
    android:id="@+id/hide_lay" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal" 
    android:weightSum="2" > 
     <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_weight="1.5" 
     android:layout_height="match_parent" > 

      <EditText 
       android:id="@+id/goal_value_2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="phone" 
       android:layout_marginLeft="40dp" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" 
       android:ems="10" /> 

     </RelativeLayout> 
     <RelativeLayout 
     android:layout_width="0dp" 
     android:layout_weight="0.5" 
     android:layout_height="match_parent" > 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:text="mm Hg" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
     /> 

     </RelativeLayout> 
    </LinearLayout> 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.5" 
    android:orientation="horizontal" 
    android:weightSum="2" > 
    </LinearLayout> 

    <RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" > 

    <Button 
    android:id="@+id/button_goal_set" 
    android:layout_width="match_parent" 
    android:layout_marginLeft="40dp" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="Set" 
    android:textColor="#ffffff" 
    android:background="#6FD0EA" /> 

    </RelativeLayout> 



    </LinearLayout> 

И мой Java-код:

final Dialog d = new Dialog(AddMeasurements.this); 

      //tell the Dialog to use the dialog.xml as it's layout description 
      d.setContentView(R.layout.measurement_goal); 
      d.setTitle("Set Goal"); 
      final EditText value = (EditText) d.findViewById(R.id.goal_value_1); 
      final EditText value2 = (EditText) d.findViewById(R.id.goal_value_2); 
      goal=(TextView)d.findViewById(R.id.textView_goal); 
      goal.setText("Set your goal for "+getIntent().getStringExtra("mname")); 
      LinearLayout l=(LinearLayout)d.findViewById(R.id.hide_lay); 
      l.setVisibility(View.GONE); 
      final TextView unit=(TextView)d.findViewById(R.id.goal_unit_1); 
      unit.setText("mg/dl"); 
      Button send = (Button) d.findViewById(R.id.button_goal_set); 

       send.setOnClickListener(new OnClickListener() { 
       @Override 
       public void onClick(View view) { 

        sp.edit().putString("Blood Glucose", value.getText().toString()+" "+unit.getText().toString()).commit(); 
        d.dismiss(); 
       } 

      }); 
       d.show(); 

Ive пытался каждую вещь, но не может исправить этот диалог, пожалуйста, помогите Thanx

+0

вы хотите ** полный экран Есть ** диалог? –

ответ

1

Изменение кода диалоговое окно с ниже код и он будет работать бы наверняка

final Dialog d = new Dialog(MainActivity.this); 

     //tell the Dialog to use the dialog.xml as it's layout description 
     d.setContentView(R.layout.dialog); 
     d.setTitle("Set Goal"); 

     //Added this lines 
     WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
     lp.copyFrom(d.getWindow().getAttributes()); 
     lp.width = WindowManager.LayoutParams.MATCH_PARENT; 
     lp.height = WindowManager.LayoutParams.MATCH_PARENT; 


     final EditText value = (EditText) d.findViewById(R.id.goal_value_1); 
     final EditText value2 = (EditText) d.findViewById(R.id.goal_value_2); 
     TextView goal=(TextView)d.findViewById(R.id.textView_goal); 
     goal.setText("Set your goal for "+getIntent().getStringExtra("mname")); 
     LinearLayout l=(LinearLayout)d.findViewById(R.id.hide_lay); 
     l.setVisibility(View.GONE); 
     final TextView unit=(TextView)d.findViewById(R.id.goal_unit_1); 
     unit.setText("mg/dl"); 
     Button send = (Button) d.findViewById(R.id.button_goal_set); 

      send.setOnClickListener(new OnClickListener() { 
      @Override 
      public void onClick(View view) { 

//    sp.edit().putString("Blood Glucose", value.getText().toString()+" "+unit.getText().toString()).commit(); 
       d.dismiss(); 
      } 

     }); 
      d.show(); 
      //added this line also 
      d.getWindow().setAttributes(lp); 
+0

это помогло .. спасибо – Prakhar

1

попробуйте изменить линейную схему к этому

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:weightSum="11" 
android:background="#ffffff"> 

и попробуйте отредактировать все свойства высоты и ширины других элементов представления, где они не должны зависеть от макета родительского диалога.

А также добавить эту строку в диалоге код

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
+0

Он спрашивает о том, что макет сжимает не как скрыть строку заголовка, – Pankaj

+0

@Clairvoyant, я знаю, что он просит сжатия. И ошибка была там в его параметре высоты и ширины макета, о котором я упомянул выше, и я сказал, что скрытая строка заголовка приводит к тому, что его предварительный просмотр макета, который он показал, не требует, чтобы –

+0

Ваш код скрывал строку заголовка также – Pankaj

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