![](/img/trans.png)
[英]How to show a button half on one layout and half on another layout in android?
[英]how to design layout button to be half one color, half other
我需要將android應用程序的按鈕設計為矩形,並變為一半一種顏色,另一半為另一種顏色。 當然是XML。
我已經試過了:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<padding
android:left="7dp"
android:top="15dp"
android:right="7dp"
android:bottom="15dp" />
<gradient
android:startColor="#a241cb"
android:endColor="#a241cb"
android:type="linear"
android:angle="90"/>
<stroke>
android:width="1dip"
android:color="#a241cb" />
<corners android:radius="0dp" />
</shape>
任何幫助表示贊賞
Try this:
首先在drwable文件夾中創建background.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#4A225E"
android:endColor="#4C4064"
android:centerColor="#B4AFC5"/>
</shape>
然后為我設置按鈕背景
您可以通過使用漸變作為背景來實現。
使用它在res/drawable
文件夾下創建一個新的XML文件,並將其命名為button_bg.xml
。 button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#D5DDE0"
android:centerColor="#e7e7e8"
android:endColor="#CFCFCF"
android:angle="270" />
</shape>
現在將其用於您的Button
如下所示:
android:background="@drawable/button_bg"
希望能幫助到你。 :)
使用這樣的9補丁(將其另存為可繪制文件夾bw_bg.9.png ):
您可以得到如下結果:
布局示例:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00f"
>
<Button
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/bw_bg"
/>
</RelativeLayout>
不必介意大小(它在2.8英寸Froyo屏幕上運行)。
同樣不要介意通知(它來自另一個正在運行的應用程序)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.