【问题标题】:Transparent Activity With Top Rounded Corners顶部圆角的透明活动
【发布时间】:2020-11-29 02:34:17
【问题描述】:

我正在设计一个顶部圆角的活动,左右两边都是透明的

我试图设计这样的东西

我创建了一个 rounded_drawable.xml 文件,并在我的 newlist.xml 中使用 android:background = "@drawable/rounded_drawable" 实现了该 xml

我的活动仍然不透明,而且它也没有圆形布局

这是我设计的

这是我的代码:

rounded_drawable.xml

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


    <solid android:color="@color/transparent"

        />

    <corners android:topRightRadius="10dp"
        android:topLeftRadius="10dp"/>
</shape>

newlist.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:background = "@drawable/rounded_drawable" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/l1"
        android:orientation="horizontal"

        >
        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/close"
            android:src="@drawable/ic_close"
            android:layout_marginTop="50dp"
            android:layout_marginLeft="100dp"
            android:layout_marginStart="100dp"
            android:layout_marginRight="15dp"
            android:layout_marginEnd="15dp"
            />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="60dp"
            android:fontFamily="@string/sans_serif_thin"
            android:text="@string/new_list"
            android:textStyle="bold"
            android:textSize="20dp"
            />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_check_circle"
            android:layout_marginTop="50dp"
            android:id="@+id/done"
            android:layout_marginLeft="15dp"
            android:layout_marginStart="15dp"

            />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/l2"
        android:orientation="horizontal"
        android:layout_below="@+id/l1"
        android:layout_marginTop="20dp"

        >
        <ImageView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:id="@+id/img"
            android:src="@drawable/ic_image"
            android:layout_marginLeft="15dp"
            android:layout_marginStart="15dp"
            />
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/listname"
            android:hint="@string/enter_the_list_name"
            android:layout_marginEnd="50dp"
            android:layout_marginRight="50dp"
            android:layout_marginTop="60dp"
            android:layout_marginLeft="15dp"
            android:layout_marginStart="15dp"
            />

    </LinearLayout>

【问题讨论】:

  • 如果新的透明activity没有覆盖整个屏幕,那为什么不用DialogActivity或者Fragment呢?正如我从上面的截图中看到的,在新的上方仍然可以看到后面的活动,这意味着透明活动大约占屏幕的 80%?我对吗?这意味着您可以改用 Fragment。
  • bcoz bro 此活动包含下面的图像,用户可以从那里选择一个图像,该图像已添加到编辑文本附近的图像视图中

标签: android xml android-layout


【解决方案1】:

在 drawable 中创建一个新的 .xml 文件并粘贴此代码

<item>
    <shape android:shape="rectangle">

    </shape>
</item>
<item
    android:top="100dp"
    android:bottom="0dp"
    android:left="-70dp"
    android:right="-70dp">

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:innerRadius="50dp"
        android:shape="rectangle"
        android:useLevel="true">

        <solid android:color="@color/colorPrimary"/>
        <corners

            android:bottomLeftRadius="0dp"
            android:topLeftRadius="250dp"
            android:topRightRadius="250dp"/>

    </shape>
</item>

也加android:background = "@drawable/yourxmlfilename"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-10
    • 2011-05-10
    • 1970-01-01
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多