简体   繁体   中英

Alert dialog box Shifting left and right

Well I have achieved the rounded corner goal in alert dialog box but it has taken all the left and right side. My question is like I want some space between left and right of the dialog box Here is my code:Custom dialog

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@drawable/custom_dialog"
    >
    <TextView
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:text="SELECT PHOTO"
          android:textSize="15dp"
          android:paddingBottom="12dp"
          android:paddingTop="12dp"
          android:layout_marginLeft="20dp"></TextView>
    <View
           android:layout_width="match_parent"
           android:layout_height="1dp"
           android:background="@color/hint_color"></View>
    <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="horizontal"
           android:paddingTop="15dp"
           android:id="@+id/Select_photo_from_Camera">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/camera_24dp"
            android:layout_marginLeft="22dp"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Camera"
            android:layout_marginLeft="10dp"
            ></TextView>
    </LinearLayout>
    <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
        <View
            android:layout_width="600dp"
            android:layout_height="1dp"
            android:layout_marginTop="10dp"
            android:background="@color/hint_color"></View>
    </LinearLayout>
    <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:orientation="horizontal"
             android:paddingTop="15dp"
             android:paddingBottom="5dp"
        >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_photo_library_black_24dp"
            android:layout_marginLeft="22dp"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gallery"
            android:layout_marginLeft="10dp"

            />

    </LinearLayout>

    </LinearLayout> 

Code for :Custom_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid
        android:color="@color/white"></solid>
    <corners
        android:radius="5dp"
        ></corners>
    <padding
        android:top="6dp"
        android:bottom="6dp"></padding>

</shape>

Here is the Output of my achievement:

https://i.stack.imgur.com/7G0Go.png

Create a inset and set as background, that may help

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/your_background_image"
    android:insetRight="25dip"
    android:insetLeft="25dip" />

use

android:background="@drawable/inset_background"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM