[英]How to Design a Android Overlay Layout
I am trying to make a alert dialog which will show like the picture. 我正在尝试制作一个警告对话框,它将显示为图片。 Im trying to use frame layout but can't make the it right like the picture.
我试图使用框架布局,但不能像图片那样使它正确。 In my current layout I used an imageView and textview.
在我目前的布局中,我使用了imageView和textview。
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src=""/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@strings/text"
/>
</FrameLayout>
<!---<other layouts--->
</LinearLayout>
A FrameLayout will stack the Views, causing them to overlap each other. FrameLayout将堆叠视图,使它们相互重叠。 If you want one directly above the other, consider using a LinearLayout with the orientation set to vertical.
如果您想要一个直接位于另一个上方,请考虑使用方向设置为垂直的LinearLayout 。
Update: Try this, replacing your FrameLayout with a LinearLayout: 更新:试试这个,用LinearLayout替换你的FrameLayout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@strings/text"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src=""/>
</LinearLayout>
Obviously fill in the src
parameter for the ImageView with your image. 显然用你的图像填写ImageView的
src
参数。
Create an Activity it represents your overlay. 创建一个代表您的叠加层的活动。
Put this in your onCreate 把它放在你的onCreate中
requestWindowFeature(Window.FEATURE_NO_TITLE);
requestWindowFeature(Window.FEATURE_NO_TITLE);
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE); //importan no title show
super.onCreate(savedInstanceState);
setContentView(R.layout.overlay);
}
put this in styles.xml 把它放在styles.xml中
<style name="FloatingPopup" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
</style>
In your manifiest declare the activity thath looks like a overlay and add the theme 在你最明确的声明活动看起来像一个叠加并添加主题
<activity
android:name=".YourOverlayActivity"
android:screenOrientation="portrait"
android:theme="@style/FloatingPopup" >
</activity>
It looks like a semitransparent activity and now you can custom with xml layout editor. 它看起来像一个半透明的活动,现在你可以使用xml布局编辑器进行自定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.