簡體   English   中英

Android:可繪制的完美圓角

[英]Android: drawable with perfect round corner

我正試着像下面那樣畫一個可繪畫的 在此輸入圖像描述

我通過以下代碼制作了這個:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@color/white"
    android:padding="10dp"
    android:orientation="vertical">

<View
    android:layout_width="40dp"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:background="@drawable/bg_round_button_green"/>

<View
    android:layout_width="40dp"
    android:layout_height="match_parent"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:background="@drawable/bg_round_button_green"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="36dp"
    android:text="Text"
    android:textColor="@color/white"
    android:textSize="22sp"
    android:gravity="center"
    android:layout_centerVertical="true"
    android:background="@color/siam_green3"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"/>

</RelativeLayout>  

bg_round_button_green.xml

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

我也試過這個:
bg_round_button_green.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FF0DAB61"/>
    <corners android:radius="100dp"/>
</shape>  

但它顯示,
在此輸入圖像描述

是否可以使用單個形狀繪制(不創建三個視圖)?

試試這個。 適合我。

<?xml version="1.0" encoding="utf-8"?>
  <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="#A5000000"/>
    <stroke android:width="0dp"
      android:color="#00FFFFFF"/>
    <padding android:left="0dp"
      android:top="0dp"
      android:right="0dp"
      android:bottom="0dp"/>
    <corners android:bottomRightRadius="10dp"
      android:bottomLeftRadius="10dp"
      android:topLeftRadius="10dp"
      android:topRightRadius="10dp"/>
  </shape>

如果你做一個可繪制的角落設置為一些大的價值:

<corners android:radius="100dp" />

沒有3次觀看,你會得到你想要的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM