FIG*_*742 9 android android-layout android-dialog
我使用Android android.app.Dialog用于创建自定义对话框(用于按钮和背景)在我的对话我有TextView 一个内部的ScrollView,而我有一个简短的文字这个节目perfecly我怎么想,但如果文字是非常大的我对话采取全屏和我想要在对话框和屏幕边缘之间有一个最小边距.
我的问题是我希望Dialog不要大于需要而且我不能在此设置修复大小?
Here is how this look today.....I what a margin like this

该 GameDialog.java
public class GameDialog extends Dialog {
public GameDialog(Context ct, int titleID, int messageID) {
super(ct, R.style.dialog_style);
this.setContentView(R.layout.dialog_layout);
}
// This exist more code but this has noting with the layout to do,only set the text and show the button that exist since the XML file.
}
Run Code Online (Sandbox Code Playgroud)
该 R.style.dialog_style
<style name="dialog_style" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">?button_image</item>
<item name="android:windowNoTitle">true</item>
<item name="android:textColor">#FF000000</item>
<item name="android:textSize">20sp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
该 R.layout.dialog_layout
<?xml version="1.0" encoding="utf-8"?>
<!-- Dialog layout that show title and a textarea, and under this allow a row of button that is center layout. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="14px"
android:layout_marginRight="14px">
<TextView
android:layout_gravity="center_vertical"
android:id="@+id/text_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
android:layout_marginLeft="14px"
android:layout_marginRight="14px">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/text_main"
android:padding="5px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</TextView>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="@+id/layout_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<!-- this will be show while need to show a button -->
<ImageView
style="?icon_size.button"
android:visibility="gone"/>
<ImageView
style="?icon_size.button"
android:visibility="gone"/>
<ImageView
style="?icon_size.button"
android:visibility="gone"/>
<ImageView
style="?icon_size.button"
android:visibility="gone"/>
<ImageView
style="?icon_size.button"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Dev*_*red 11
框架实际上是在背景图像本身上执行此操作.换句话说,如果你看一下为框架定义的主题,它们的windowBackground属性只是一个清晰的颜色,即:
<item name="android:windowBackground">@android:color/transparent</item>
Run Code Online (Sandbox Code Playgroud)
然后放置在根布局项目上的背景图像是一个9补丁,在所有边上都有内置填充(即图像中内置了额外的空间,因此当图像拉伸以填充屏幕时,您仍然可以看到边缘) .看看AOSP源代码中的一个面板,了解我的意思(链接).
所以对于你的解决方案,我会推荐两件事:
windowBackground上面描述的修改您的自定义样式对于第2步,如果您的图片目前是9补丁,请执行与Google相同的操作.如果您使用XML创建图像,则可以使用<layer-list>类似以下示例的方法将可见矩形嵌入到另一个内部并使用填充:
<?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="@android:color/transparent" />
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item>
<!-- This shape will be inset by the padding set above -->
<item>
<shape android:shape="rectangle" >
<solid android:color="#262626" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,填充不会传输到内容,因此您还需要向根布局项添加填充以使内容边界与图像显示相匹配.
| 归档时间: |
|
| 查看次数: |
8645 次 |
| 最近记录: |