UI对齐 - 无法解决

时间:2014-04-21 05:27:37

标签: android xml android-layout user-interface

我尝试了很多方法,但无法解决此对齐问题。而且我不确定我哪里出错了。

我的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical"
    android:background="@color/popover">

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textColor="#000000"
            android:layout_marginTop="15dp"
            android:layout_marginBottom="2dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textColor="#000000"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textColor="#000000"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textColor="#000000"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:layout_margin="5dp"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Small Text"
            android:textColor="#000000"
            android:layout_margin="5dp"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Small Text"
            android:textColor="#000000"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="15dp"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp" >

            <ImageButton
                android:id="@+id/locationalert_dont"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:background="@drawable/dontallow_btnaction" />

            <ImageButton
                android:id="@+id/locationalert_ok"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dp"
                android:background="@drawable/ok_btnaction" />

        </LinearLayout>

    </LinearLayout>

和班级档案:

public void showLocationDialog()
    {

        Dialog dialog = new Dialog(Homescreen.this);
        dialog.setContentView(R.layout.locationalert);

        TextView tv1 = (TextView)dialog.findViewById(R.id.textView1);

        TextView tv2 = (TextView)dialog.findViewById(R.id.textView2);

        TextView tv3 = (TextView)dialog.findViewById(R.id.textView3);

        TextView tv4 = (TextView)dialog.findViewById(R.id.textView4);

        TextView tv5 = (TextView)dialog.findViewById(R.id.textView5);

        TextView tv6 = (TextView)dialog.findViewById(R.id.textView6);

        ImageButton ok = (ImageButton)dialog.findViewById(R.id.locationalert_ok);

        ImageButton dont = (ImageButton)dialog.findViewById(R.id.locationalert_dont);

        dialog.show();

    }

实际上我在课堂上有一个按钮,然后点击它弹出这个对话框。但对话框显示为

enter image description here

在截图中,我得到一个标题黑条以及弹出对话框,我不知道如何删除它。

任何相关的答案都是可取的。提前致谢 。

5 个答案:

答案 0 :(得分:1)

尝试以下代码: -

final Dialog dialog = new Dialog(ActivityName.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // hide title bar
dialog.setContentView(R.layout.vip_services_other_dialog);

// hide black background
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

refer link

答案 1 :(得分:1)

使用

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);  

请同时通过:

Android Window and Related FlagsDialogs

答案 2 :(得分:0)

在XML(locationalert)中,将“线性布局背景”设置为:

android:background="@android:color/transparent"

并在showLocationDialog()方法中添加

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(R.color.YOURCOLOR));

答案 3 :(得分:0)

这是您的问题的解决方案

 Dialog dialog = new Dialog(Homescreen.this,android.R.style.Theme_Translucent_NoTitleBar );
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.locationalert);

答案 4 :(得分:0)

您可以隐藏标题栏和对话框的背景,如下所示:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

希望这会有所帮助.. :)