本文介绍了Android的自定义对话框,从布局膨胀 - 对齐问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义对话框,whick我从dialog.xml膨胀。当我打开对话框中,它看起来像如下图所示。我越来越ListView和它下面的(OK)按钮之间的一些空间。我想消除列表视图和下面的按钮之间的空间。
我怎样才能做到这一点,?

dialog.xml

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / RelativeLayout1
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =FILL_PARENT>    < ListView控件
        机器人:ID =@ + ID / listViewDialog
        机器人:layout_width =match_parent
        机器人:layout_height =FILL_PARENT
        机器人:layout_above =@ + ID /按钮1
        机器人:layout_below =@ + ID / ImageView1>
    < /&的ListView GT;    <复选框
        机器人:ID =@ + ID / checkBoxAll
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_above =@ + ID / ListView1的
        机器人:layout_alignParentRight =真
        机器人:layout_marginBottom =15dp
        机器人:layout_marginRight =25dp
        机器人:layout_marginTop =15dp
        机器人:文字=/>    < ImageView的
        机器人:ID =@ + ID / ImageView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentLeft =真
        机器人:layout_alignParentTop =真
        机器人:layout_marginBottom =15dp
        机器人:layout_marginLeft =14dp
        机器人:layout_marginTop =15dp
        机器人:背景=#FFFFBB33
        机器人:contentDescription =@字符串/ APP_NAME
        机器人:scaleType =中心
        机器人:SRC =@绘制/ alert_dialog_icon/>    <的TextView
        机器人:ID =@ + ID / textView1
        机器人:layout_width =128dp
        机器人:layout_height =match_parent
        机器人:layout_above =@ + ID / listViewDialog
        机器人:layout_marginBottom =15dp
        机器人:layout_marginTop =15dp
        机器人:layout_toRightOf =@ + ID / ImageView1
        机器人:重力=center_vertical
        机器人:文字=分类
        机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceLarge?    <的TextView
        机器人:ID =@ + ID / textView2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignBaseline =@ + ID / textView1
        机器人:layout_alignBottom =@ + ID / textView1
        机器人:layout_toLeftOf =@ + ID / checkBoxAll
        机器人:文字=全部
        机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceLarge?    <按钮
        机器人:ID =@ + ID /按钮1
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:文字=OK/>< / RelativeLayout的>


解决方案

这是很容易..
你有2 approchase:
1)创建根realtivelayout有机器人:layout_height =wrap_cotent,并在同一时间在ListView具有相同。这将缩小所有对话框的大小向右(无空格)的大小。
2)*更recomended,有根是一个的LinearLayout并给它一些wightsum,然后把其他意见这根,并给他们一些layout_wight,这样,你知道在任何屏幕分辨率,你有同样的比例予以你屏幕。

I have an custom dialog, whick i am inflating from dialog.xml. when I open the dialog it looks something like shown below. I am getting some space between listview and the (OK) button below it. I want to eliminate this space between the list view and the Button below it.How can i do this,?

dialog.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent" >

    <ListView
        android:id="@+id/listViewDialog"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/button1"
        android:layout_below="@+id/ImageView1" >
    </ListView>

    <CheckBox
        android:id="@+id/checkBoxAll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/listView1"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="15dp"
        android:layout_marginRight="25dp"
        android:layout_marginTop="15dp"
        android:text="" />

    <ImageView
        android:id="@+id/ImageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="15dp"
        android:layout_marginLeft="14dp"
        android:layout_marginTop="15dp"
        android:background="#FFFFBB33"
        android:contentDescription="@string/app_name"
        android:scaleType="center"
        android:src="@drawable/alert_dialog_icon" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="128dp"
        android:layout_height="match_parent"
        android:layout_above="@+id/listViewDialog"
        android:layout_marginBottom="15dp"
        android:layout_marginTop="15dp"
        android:layout_toRightOf="@+id/ImageView1"
        android:gravity="center_vertical"
        android:text="Categories"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignBottom="@+id/textView1"
        android:layout_toLeftOf="@+id/checkBoxAll"
        android:text="All"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="OK" />

</RelativeLayout>
解决方案

this is really easy..you have 2 approchase:1) create the root realtivelayout to have android:layout_height="wrap_cotent", and in the same time the ListView to have the same. this will shrink the sizes of the all dialog to the right (no space) size.2) *more recomended , have the root to be a Linearlayout and give it some wightsum, then put the other views in this root, and give them some layout_wight, this way you know the in any screen resolution you have the same porportion of your screen.

这篇关于Android的自定义对话框,从布局膨胀 - 对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 23:13