Android 片段之间的阴影分隔符 [英] Shadow Separator Between Android Fragments

查看:23
本文介绍了Android 片段之间的阴影分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于平板电脑的 ICS Gmail 应用程序的布局(左侧是 ListFragment,右侧是内容),我想知道如何构建布局以便有一个两个片段之间的阴影分隔符(就像在 Gmail 应用中一样,如下所示)

I have a layout similar to the ICS Gmail app for tablets (ListFragment on the left and content on the right) and I was wondering how I could go about constructing the layouts such that there is a shadow separator between the two fragments (like in the Gmail app, shown below)

.

另外,由于这适用于这个问题,我怎样才能在活动列表项的布局中拥有那个漂亮的三角形/箭头标记?我假设要实现这一点,ListView 本身必须位于上方阴影层",但我不知道如何创建它.

Also, as this is applicable to this question, how can I have that nice triangle/arrow marker in the active list item's layout? I assume to implement this, the ListView itself must lie above the shadow "layer", but I have no idea how to create that.

推荐答案

只是为了让大家知道(因为似乎缺乏有关此主题的信息),这是在个人的后台选择器 XML 中实现的列表行视图.例如,这是主屏幕的布局,

Just to let everyone know (because there seems to be a lack of information out there on this topic), this is achieved within the background selector XML of the individual list rows' view. For example, this is the main screen's layout,

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list_row"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@drawable/list_item_selector">

    ...<!-- Rest of layout goes here -->

</RelativeLayout>

但神奇的是list_item_selector:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/list_pressed" />
    <item android:state_activated="true" android:drawable="@drawable/list_arrow_activated"  />
    <item android:drawable="@drawable/list_default" />
</selector>

通过像这样将这些定义为 9-patch drawable,您可以让每个列表项将其阴影的宽度值贡献给中间的那条线,当它被激活时,那段阴影将被一个箭头替换.我希望这对某人有所帮助,因为它肯定对我有帮助!

By defining these as 9-patch drawables like this, you can have each list item contribute it's width worth of shadow to that line in the middle, and when it is activated, that segment of shadow will be replaced by an arrow. I hope this helps someone, as it's sure helped me!

这篇关于Android 片段之间的阴影分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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