繁体   English   中英

如何将布局按钮设计成一半一种颜色,另一半

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM