半圈形状不起作用 [英] Half circle shape not work

查看:52
本文介绍了半圈形状不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在development IDE preview中创建半圆形背景,但是它在模拟器中启动时不起作用.

I try to create half circle background, in development IDE preview it works, but when I launch in emulator it doesn't work.

这是我的形状代码:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:height="50dp">
        <shape>
            <solid android:color="@color/colorAccentDark" />
        </shape>
    </item>
    <item android:top="-500dp" android:bottom="0dp" android:left="-100dp" android:right="-100dp">
        <shape>
            <corners android:radius="500dp" />
            <solid android:color="@color/colorAccentDark" />
        </shape>
    </item>
</layer-list>

这是我的布局代码:

<?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:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/background_profile"
        android:layout_weight="1">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/profile_avatar"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:src="@drawable/ic_default_avatar"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="50dp"/>

        <TextView
            android:id="@+id/profile_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/profile_avatar"
            android:layout_marginTop="20dp"
            android:textColor="@color/neutralWhite"
            android:textStyle="bold"
            android:textSize="18sp"
            android:text="Avatar Ang"/>

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="4.04">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello Android!"/>

    </RelativeLayout>

</LinearLayout>

也许还有其他调整方法可以解决? 谢谢

Maybe any other tweak to handle that? Thank you

推荐答案

您不能从xml创建半圆.但是您可以使用具有适当边距&的圆圈来实现您想要的目标填充.

You cannot create a semicircle from xml. but you could achieve what you are looking for using a circle with appropriate margin & padding.

您可以使用圆形.xml文件. 创建一个固定大小的圆圈,如下所示:

You can use a circle shape .xml file. Create a fixed sized circle like this:

示例:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="oval"
       android:useLevel="false" >
   <solid android:color="#006AC5" />
   <size
    android:height="50dp"
    android:width="50dp" />
</shape>

这篇关于半圈形状不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆