自定义对话框如视图

时间:2016-12-07 10:59:58

标签: android

我正在尝试创建类似于以下的警报。我用ediitext替换了图像中的文本。

picture

    #snow{
    background-image: url('/assets/images/s1.png'),
            url('/assets/images/s2.png'),
            url('/assets/images/s3.png');
    height: 100%;
        pointer-events: none;
    left: 0;
    position: absolute;
    top: 0;
    width: 100%;
    z-index:1;
    -webkit-animation: snow 10s linear infinite;
    -moz-animation: snow 10s linear infinite;
    -ms-animation: snow 10s linear infinite;
    animation: snow 10s linear infinite;
}
/*Keyframes*/
@keyframes snow { 0% { background-position: 500px 0px, 120px 0px, -100px 0px; }
       10% { background-position: 500px 100px, 120px 40px, -100px 30px; }
       20% { background-position: 500px 200px, 120px 80px, -100px 60px; }
       30% { background-position: 500px 300px, 120px 120px, -100px 90px; }
       40% { background-position: 500px 400px, 120px 160px, -100px 120px; }
       50% { background-position: 500px 500px, 120px 200px, -100px 150px; }
       60% { background-position: 500px 600px, 120px 240px, -100px 180px; }
       70% { background-position: 500px 700px, 120px 280px, -100px 210px; }
       80% { background-position: 500px 800px, 120px 320px, -100px 240px; }
       90% { background-position: 500px 900px, 120px 360px, -100px 270px; }
       100% { background-position: 500px 1000px, 120px 400px, -100px 300px; } }

@-moz-keyframes snow {
0% {background-position: 0px 0px, 0px 0px, 0px 0px;}
100% {background-position: 500px 1000px, 400px 400px, 300px 300px;}
}

@-webkit-keyframes snow {
0% {background-position: 0px 0px, 0px 0px, 0px 0px;}
 100% {background-position: 500px 1000px, 400px 400px, 300px 300px;}
}

@-ms-keyframes snow {
0% {background-position: 0px 0px, 0px 0px, 0px 0px;}
 100% {background-position: 500px 1000px, 400px 400px, 300px 300px;}
}

我让根布局变得透明,我让孩子有了白色背景。我已将imageview的margintop设置为-20,因此它会向上突出但我无法获得相同的效果。为什么呢?

3 个答案:

答案 0 :(得分:3)

您可以使用FrameLayout在另一个视图上方添加视图并为其添加边距,使其看起来像是同一布局的一部分。

<?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="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:background="@android:color/transparent"
            android:orientation="vertical">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                    <EditText
                        android:ems="10"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@android:color/white"
                        android:inputType="textMultiLine"
                        android:layout_marginTop="20dp"
                        android:lines="8"
                        android:maxLines="10"
                        android:minLines="6"
                        android:scrollbars="vertical" />

                <ImageView
                    android:layout_marginTop="0dp"
                    android:layout_width="wrap_content"
                    android:layout_height="50dp"
                    android:layout_gravity="center|top"
                    android:src="@drawable/ic_launcher" />
            </FrameLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:background="@android:color/white"
                android:weightSum="2">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@android:color/black"
                    android:text="Submit"
                    android:textColor="#FFFFFF" />

                <View
                    android:layout_width="4dp"
                    android:layout_height="match_parent"
                    android:background="@android:color/transparent" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@android:color/black"
                    android:text="Cancel"
                    android:textColor="#FFFFFF" />

            </LinearLayout>
        </LinearLayout>

答案 1 :(得分:2)

给定对话框的XML -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="280dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:color/transparent"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardCornerRadius="4dp"
            android:layout_marginTop="32dp"
            android:id="@+id/congratulation_card"
            app:cardBackgroundColor="#FAFAFA"
            app:cardElevation="0dp"
            android:layout_gravity="bottom">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:id="@+id/title"
                android:textSize="18sp"
                android:textColor="@android:color/primary_text_light"
                android:layout_marginTop="48dp"
                android:text="Congratulations"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="24dp"
                android:layout_marginLeft="32dp"
                android:textSize="16sp"
                android:layout_marginRight="32dp"
                android:id="@+id/message"
                android:gravity="center"
                android:text="You've just displayed this awesome pop up view "
                />
            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Let's read"
                android:id="@+id/read_btn"
                android:layout_marginTop="32dp"
                android:layout_marginRight="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginBottom="16dp"
                android:textColor="@android:color/white"
                android:background="@drawable/primary_button"
                />
        </LinearLayout>
        </android.support.v7.widget.CardView>

            <ImageView
                android:layout_width="64dp"
                android:layout_height="64dp"
                android:padding="1dp"
                android:src="@drawable/tick_green"
                android:background="@drawable/circular_tick"
                android:layout_gravity="center_horizontal|top"
                />

    </FrameLayout>
</LinearLayout>

Drawable Circular tick ---

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid
        android:color="#FAFAFA"
       />

    <size
        android:width="120dp"
        android:height="120dp"/>
</shape>

可绘制主按钮 -

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners
        android:radius="4dp" />
    <gradient
        android:startColor="@color/colorPrimaryLight"
        android:endColor="@color/colorPrimary"  />
    <padding
        android:left="10dp"
        android:top="10dp"
        android:right="10dp"
        android:bottom="10dp" />
</shape>

为我工作。

答案 2 :(得分:1)

你不应该使用LinearLayout,你应该使用RelativeLayout.Be的情况下,子视图不能超出父视图