Android 在对话框边界外查看
我想要这样的东西:Android 在对话框边界外查看,android,android-layout,android-ui,android-dialog,Android,Android Layout,Android Ui,Android Dialog,我想要这样的东西: <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <RelativeLayout android:layout_marginTop="30dp" android:layout_width="match_parent" android:layout_heigh
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@android:color/darker_gray">
<TextView
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="blablabla"/>
</RelativeLayout>
<ImageView
android:id="@+id/iv1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_launcher"/>
</RelativeLayout>
用户配置文件图片在对话框边界上“弹出”
我已经尝试过了所有的方法:在日光下对所有可能的组合进行剪裁,在对话框之后动态创建视图并将其添加到根内容视图,使用单独的视图并使用dialog.setCustomTitle()加载该视图,对图像onDraw()进行黑客攻击方法和应用各种边界/位置破解——但不管是什么,图像总是被剪裁并分成两半
我甚至对Play Store APK进行了反编译,看看他们是如何做到的。不幸的是,资源文件没有透露太多信息,我在Smali中找不到任何东西
有人能帮忙吗?请-(
编辑:我只是专门讨论对话框顶部的用户配置文件图像,而不是对话框本身。对话框方法:
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>
结果首先,您应该使对话框的背景透明。 对于DialogFragment:。 对于AlertDialog:。 其次,以如下方式组合布局:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@android:color/darker_gray">
<TextView
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="blablabla"/>
</RelativeLayout>
<ImageView
android:id="@+id/iv1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_launcher"/>
</RelativeLayout>
其中iv1是标题图像,看起来他们只是在ImageView中有一个圆形图像,并且有一个从顶部开始的边距为imagesize的一半的布局 所以,如果我的图像大小是
100px
,我应该使用50dip
来显示所有屏幕中居中的图像
dialog.xml
输出
为了改进@MHP,您还可以添加cardView,使对话框的角落变圆
比如:
<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:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="57dp"
android:background="@android:color/transparent"
android:orientation="vertical">
<android.support.v7.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/llMainContents"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FAFAFA"
android:orientation="vertical"
app:cardCornerRadius="2dp" />
</LinearLayout>
<ImageView
android:id="@+id/ivIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="8dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="@null"
android:src="@mipmap/ic_launcher" />
</RelativeLayout>
您是否尝试过将活动
与对话主题
结合使用?()太棒了,谢谢!我想使用AlertDialog,但透明度不起作用。这为我带来了窍门:惊人的答案。最重要的是,我测试了解决方案,但您的答案是完美的。而且效果很好。您救了我一天。
<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:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="57dp"
android:background="@android:color/transparent"
android:orientation="vertical">
<android.support.v7.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/llMainContents"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FAFAFA"
android:orientation="vertical"
app:cardCornerRadius="2dp" />
</LinearLayout>
<ImageView
android:id="@+id/ivIcon"
android:layout_width="100dp"
android:layout_height="100dp"
android:padding="8dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="@null"
android:src="@mipmap/ic_launcher" />
</RelativeLayout>