开发者

Android Custom Dialog stretches across screen instead of wrapping content

开发者 https://www.devze.com 2023-03-14 01:12 出处:网络
I\'m trying to make a custom dialog, and for some reason it stretches out horizontally across the entire screen even though i set it\'s width to wrap_content...

I'm trying to make a custom dialog, and for some reason it stretches out horizontally across the entire screen even though i set it's width to wrap_content...

Here is the XML file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content" android:layout_height="wrap_content">

    <Button android:id="@+id/btnContinue"
开发者_如何学运维        android:layout_marginRight="10dp" android:layout_marginTop="60px"
        android:layout_alignParentRight="true" android:background="@drawable/btn_dialog_continue"
        android:layout_width="wrap_content" android:layout_height="wrap_content" />

    <Button android:id="@+id/btnCancel" android:layout_alignTop="@+id/btnContinue"
        android:layout_toLeftOf="@id/btnContinue" android:background="@drawable/btn_dialog_cancel"
        android:layout_width="wrap_content" android:layout_height="wrap_content" />

    <EditText android:id="@+id/input" android:layout_width="wrap_content"
        android:layout_marginBottom="4dp" android:layout_alignLeft="@id/btnCancel"
        android:background="@drawable/bg_text_round"
        android:layout_alignParentRight="true" android:layout_height="56px"
        android:layout_marginRight="15px" />
    <ImageView android:id="@+id/thumb" android:layout_width="136px"
        android:layout_toLeftOf="@id/input" android:layout_height="105px"
        android:paddingLeft="18px" android:paddingTop="20px"
        android:paddingRight="20px" android:paddingBottom="18px"
        android:layout_centerVertical="true" android:background="@drawable/bg_tagrow_item" />
</RelativeLayout>

And the java code:

    final Dialog dialog = new Dialog(this, R.style.TextDialog);
    dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
    dialog.setContentView(R.layout.text_dialog);
    dialog.setTitle(titleId);
    ImageView thumb = (ImageView) dialog.findViewById(R.id.thumb);
    Button btnContinue = (Button) dialog.findViewById(R.id.btnContinue);
    Button btnCancel = (Button) dialog.findViewById(R.id.btnCancel);
    final EditText input = (EditText) dialog.findViewById(R.id.input);

    thumb.setImageBitmap(mTagAdapter.mCollection.mThumbCache[mTagAdapter.mCollection.names
            .indexOf(getTargets()[0])]);

    dialog.show();
    dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_dialog_menu_generic);

Thanks


sorry for mistake. now this is the simple example "RelativeLayout" it shows that list item by separating by ":"

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10sp">
<TextView
  android:id="@+id/infoid"
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" /> 
<TextView
  android:id="@+id/infoidcolon"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text=": "
  android:layout_toRightOf="@id/infoid" />
<TextView
  android:id="@+id/rowid"
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"  
  android:layout_toRightOf="@id/infoidcolon" />
<TextView
  android:id="@+id/rowidcolon"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text=": "
  android:layout_toRightOf="@id/rowid" />
<TextView
  android:id="@+id/name"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toRightOf="@id/rowidcolon" />
<TextView
  android:id="@+id/namecolon"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text=": "
  android:layout_toRightOf="@id/name" />
<TextView
  android:id="@+id/phoneno"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toRightOf="@id/namecolon" />
<TextView
  android:id="@+id/phonecolon"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text=": "
  android:layout_toRightOf="@id/phoneno" />
<TextView
  android:id="@+id/sl"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toRightOf="@id/phonecolon" />
  <TextView
  android:id="@+id/slcolon"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text=": "
  android:layout_toRightOf="@id/sl" />
<TextView
  android:id="@+id/nameinfo"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toRightOf="@id/slcolon" />
<TextView
  android:id="@+id/nameinfocolon"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text=": "
  android:layout_toRightOf="@id/nameinfo" />
<TextView
  android:id="@+id/qty"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_toRightOf="@id/nameinfocolon" />

</RelativeLayout>


You need to write this line into "RelativeLayout" tag as a attribute.

android:orientation="vertical"
0

精彩评论

暂无评论...
验证码 换一张
取 消