简体   繁体   English

如何使用3个视图而不是9个视图实现此布局?

[英]How can I achieve this layout using 3 views instead of 9?

在此处输入图片说明

I have this layout currently implemented HERE and uses 9 Views just for the Buttons at the top + bottom and the TextView in the center. 我目前在这里实现了此布局,仅在顶部+底部的按钮和中心的TextView使用9个视图。 For making this with 3 Views, here is what I understand, we need a LinearLayout horizontal that has the 3 TextViews and they need to use Drawable Tops and Bottoms, the problem is as per the GIF, notice how the top background + icon changes at the same time, I wrote a selector that combines a layer list but it doesn't work. 为了使用3个视图实现此功能,这是我的理解,我们需要一个具有3个TextViews的LinearLayout水平控件,它们需要使用Drawable Tops和Bottoms,问题出在GIF上,请注意顶部背景+图标在同时,我写了一个选择器,它结合了一个图层列表,但是不起作用。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <layer-list>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="@android:color/transparent"/>
                </shape>
            </item>
            <item>
                <bitmap
                    android:gravity="center"
                    android:src="@drawable/ic_menu_down_colored"/>
            </item>
        </layer-list>
    </item>
    <item>
        <layer-list>
            <item>
                <shape android:shape="rectangle">
                    <solid android:color="@color/purple"/>
                </shape>
            </item>
            <item>
                <bitmap
                    android:gravity="center"
                    android:src="@drawable/ic_menu_down_transparent"/>
            </item>
        </layer-list>
    </item>
</selector>

Any ideas and suggestions on how to achieve this with a compound drawable created in XML or code is highly appreciated 高度赞赏有关如何使用以XML或代码创建的复合可绘制对象实现此目标的任何想法和建议

There are similar but slightly different implementations on this post . 这篇文章有类似但略有不同的实现。 One of these may help you achieve what you've stated in the question. 其中之一可以帮助您实现问题中已说明的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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