如何实现弯曲自定义按钮水平在Android的? [英] How to implement curved custom buttons horizontally in Android?

查看:221
本文介绍了如何实现弯曲自定义按钮水平在Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图实施过彼此重叠水平自定义按钮。点击的按钮将是光明的,其余的将淡出了一点,他们的重叠边界到选择的按钮将被隐藏背后。这里是澄清我谈论的图像

I am trying to implement custom buttons that overlap over each other horizontally. The clicked button will be bright and the rest will fade a little and their the overlapped border to the selected button would be hidden behind. Here is an image to clarify what I am talking about.

要做到这一点我做了一个线性布局与具有线性子的布局包裹每个按钮而是结束了怪异的按钮伸出父布局,尽管我打了一点点他们的宽度和高度,水平方向。有人可以给我如何做到这一点的提示?

To do this I made a Linear Layout with horizontal orientation that has child Linear Layouts that wrap each button but that ended up with weird buttons stick out of the parent layout even though I played a little with their width and height. Can someone give me a hint on how to do this?

推荐答案

这是你的布局文件应该怎么看起来像: -

This is how Your Layout file should look like:-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@drawable/round_background"
    android:orientation="horizontal"
    android:weightSum="3"
    tools:context="com.example.curved.MainActivity" >

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="1dp"
        android:layout_marginLeft="1dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="1dp"
        android:layout_weight="1"
        android:background="@drawable/round_background"
        android:gravity="center"
        android:text="Line"
        android:textSize="20sp" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="1dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="1dp"
        android:layout_weight="1"
        android:background="@drawable/round_background_white"
        android:gravity="center"
        android:text="Lyft"
        android:textColor="#ff33b5e5"
        android:textSize="20sp" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="1dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="1dp"
        android:layout_marginTop="1dp"
        android:layout_weight="1"
        android:background="@drawable/round_background"
        android:gravity="center"
        android:text="Plus"
        android:textSize="20sp" />

</LinearLayout>

round_background.xml为灰色背景

round_background.xml for grey background

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="10dp"
    android:shape="rectangle" >

    <!-- you can use any color you want I used here gray color -->
    <solid android:color="#ABABAB" />

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

</shape>

round_background_white.xml白色按钮

round_background_white.xml for white button

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

    <!-- you can use any color you want I used here white color -->
    <solid android:color="#FFF" />

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

</shape>

最终结果

在这里输入的形象描述

和上单击事件变化的背景和文本颜色就是这样,我与XML格式显示它。

And on click event change backgrounds and text color like this ,I have shown it with xml.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@drawable/round_background"
    android:orientation="horizontal"
    android:weightSum="3"
    tools:context="com.example.curved.MainActivity" >

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="1dp"
        android:layout_marginLeft="1dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="1dp"
        android:layout_weight="1"
        android:background="@drawable/round_background_white"
        android:gravity="center"
        android:text="Line"
        android:textColor="#ff33b5e5"
        android:textSize="20sp" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="1dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="1dp"
        android:layout_weight="1"
        android:background="@drawable/round_background"
        android:gravity="center"
        android:text="Lyft"
        android:textSize="20sp" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="1dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="1dp"
        android:layout_marginTop="1dp"
        android:layout_weight="1"
        android:background="@drawable/round_background"
        android:gravity="center"
        android:text="Plus"
        android:textSize="20sp" />

</LinearLayout>

在这里输入的形象描述

这篇关于如何实现弯曲自定义按钮水平在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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