自定义的视图图像外边框对话框? [英] Custom dialog with Image outside boundaries of the view?
问题描述
我试图创建一个自定义对话框
喜欢的这,我按照此<一个href=\"http://stackoverflow.com/questions/20258730/custom-dialog-with-close-button/29026658#29026658\">answer但改变 layout_gravity
这个的android:layout_gravity =CENTER_HORIZONTAL |顶
键,它把对中心的对话框
我愿意,但问题是,如果我想要把的ImageView
大它破坏了 XML
,还有对话框
本身是太小了,因为我只有一个的TextView
和的EditText
所以我做错了吗?
I'm trying to create a Custom Dialog
like this, I'm following this answer but changing the layout_gravity
to this android:layout_gravity="center_horizontal|top"
and it puts on the center of the Dialog
as I want, but the thing is that if I want to put the ImageView
bigger it destroys the xml
, also the Dialog
itself it's too small because I only have a TextView
and an EditText
so what I'm doing wrong?
这是我的XML。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#fff"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose the receiver"
android:textColor="@color/blue"
android:textSize="16dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@drawable/edittext_style"
android:hint="Username"
android:padding="5dp"
android:singleLine="true"
android:textColorHint="@color/wallet_holo_blue_light" />
</LinearLayout>
</FrameLayout>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_horizontal|top"
android:src="@drawable/icon_mail" />
</FrameLayout>
</FrameLayout>
输出
另外,我在可绘制
来把它放在对话框
以创建边框roundered颜色,如果我把它放在的LinearLayout
它不会显示出来。
Also I've a Drawable
to put it on the Dialog
to create a border roundered with color and if I put it on LinearLayout
it doesn't show up.
这是rounded_border.xml
This is the rounded_border.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="@color/white" />
<corners android:radius="12dip" />
<stroke
android:width="1dip"
android:color="@color/wallet_holo_blue_light" />
</shape>
</item>
如果我修改的ImageView
的大小会发生这样的:
If I change the size of the ImageView
happens this :
推荐答案
您可以试试这个:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:background="#fff" />
</LinearLayout>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerInParent="true"
android:src="@drawable/icon_mail" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#fff"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose the receiver"
android:textColor="@color/blue"
android:textSize="16dp" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@drawable/edittext_style"
android:hint="Username"
android:padding="5dp"
android:singleLine="true"
android:textColorHint="@color/wallet_holo_blue_light" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
只是重要的是你保持(在本例中30dp)与父 RelativeLayout的
高度对齐的ImageView
宽度/高度。
Just important that you keep ImageView
width/height (30dp in the example) aligned with parent RelativeLayout
height.
这篇关于自定义的视图图像外边框对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!