2017-10-14 19 views
0

私はAndroidで初心者です。私には小さな問題が1つあります。私のアラートの幅が短すぎます。私のアラートサイズがAndroidに正しく表示されていませんか?

スクリーンショット:

<?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"> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:orientation="vertical"> 


    <android.support.v7.widget.AppCompatTextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:text="@string/name" 
     /> 
    <android.support.v7.widget.AppCompatTextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="15dp" 
     android:text="Hari" 
     android:textColor="@color/colorPrimaryBlack" 
     /> 


    <android.support.v7.widget.AppCompatTextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="15dp" 
     android:text="@string/customer_id1" 
     /> 
    <android.support.v7.widget.AppCompatTextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="15dp" 
     android:text="96" 
     android:textColor="@color/colorPrimaryBlack" 
     /> 
    <android.support.v7.widget.AppCompatTextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="15dp" 
     android:text="@string/mobile" 
     /> 
    <android.support.v7.widget.AppCompatTextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="15dp" 
     android:text="7826963223" 
     android:textColor="@color/colorPrimaryBlack" 
     /> 
    <android.support.v7.widget.AppCompatTextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="15dp" 
     android:text="@string/pickup_address" 
     /> 

    <android.support.v7.widget.AppCompatTextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="15dp" 
     android:text="ponmeni Muniyandi kovil main road" 
     android:textColor="@color/colorPrimaryBlack" 
     /> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:paddingBottom="1.0dip" 
     android:paddingLeft="4.0dip" 
     android:paddingRight="4.0dip" 
     android:layout_marginTop="15dp" 
     android:paddingTop="5.0dip"> 

     <Button 
      android:id="@+id/Accept" 
      android:layout_width="0.0dip" 
      android:layout_height="fill_parent" 
      android:layout_marginLeft="15dp" 
      android:layout_weight="1.0" 
      android:background="@drawable/btn_rounded_primary" 
      android:textColor="@color/colorPrimarywhite" 
      android:text="@string/btn_accept" /> 
     <Button 
      android:id="@+id/Decline" 
      android:layout_width="0.0dip" 
      android:layout_height="fill_parent" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="15dp" 
      android:layout_weight="1.0" 
      android:background="@drawable/btn_rounded_black" 
      android:text="@string/btn_decline" 
      android:textColor="@color/colorPrimarywhite" /> 
    </LinearLayout> 
</LinearLayout> 
</LinearLayout> 
+1

fill_parentは廃止のでmatch_parentでfill_parentを置き換える最初 –

+1

警告ダイアログのためのあなたのコードを共有する(https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT)[参照]とあなたにこのダイアログを膨らませるJavaコードを表示してください。 – UltimateDevil

+0

をメモとして、私は拒否ボタンが常に戻るボタンの横にあるべきだと思います。これはデバイスごとに異なることにも注意してください。 – Doomsknight

答えて

1

このセット絶頂ダイアログのレイアウトを試してみてください。ここ

enter image description here

は、設計xmlです幅をプログラムで使用する Window

Dialog dialog = new Dialog(this); 
    dialog.setContentView(R.layout.your_layout); 

    Window window = dialog.getWindow(); 
    window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); 
    window.setGravity(Gravity.CENTER); 

    dialog.show(); 

もこの値は、APIレベル8で始まる非推奨とMATCH_PARENTに置き換えられandroid:layout_width="fill_parent" beacuseあなたLinearLayout

に使用android:layout_width="match_parent"の代わりandroid:layout_width="fill_parent"を使用しています。

-1

あなたは、このことにより、アラートボックスのサイズを制御することができます:

alertDialog.getWindow().setLayout(100, 400); //Controlling width and height. 
-1

これは、あなたの問題を確実に解決します。

dialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
関連する問題