2017-01-10 20 views
0

ダイアログボックスの中央にImageViewを置いてカスタムダイアログを作成しています。カスタムダイアログの中央上部にimageviewを配置する方法は?

enter image description here

+0

同じものに対してFrameLayoutを使用することができます。最初の要素をOrange Lineボックスにし、上からいくらかの余白を付けます。 2.最初に配置されたレイアウトの上に表示される、中心重力、framelayoutの2番目のビューを持つ画像ビューを2番目に作成します。 うまくいくと思います。 –

答えて

1

をこれら二つのプロパティを設定します。

ダイアログ方法:

Dialog dialog = new Dialog(this); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.mhp); 
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
    dialog.show(); 

mhp.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@android:color/transparent" > 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="57dp" 
    android:background="#f00" 
    android:orientation="vertical" > 
</LinearLayout> 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 

結果(BGを避ける)

enter image description here

+0

こんにちは、ありがとう....それは働いた:) – User

0

セットこの相対的なレイアウトボックスでImageViewのとは、あなたがあなたの考えに従ってLinearLayoutの内側に、あなたのViewsを置くことができImageViewのタグに

android:layout_centerHorizontal="true" 
    android:layout_marginTop="-50dp" 
+0

どのプロパティ? – User

1

この

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 




<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="300dp" 
    android:layout_marginTop="90dp" 

    android:background="@color/colorPrimary" 
    > 
    </LinearLayout> 

<ImageView 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_marginTop="20dp" 
    android:layout_gravity="center_horizontal" 
    android:src="@mipmap/ic_launcher" 
    /> 
</FrameLayout> 
をお試しください
関連する問題