English 中文(简体)
上方的绘图选择器 - 用于基本的线性布局吗?
原标题:Draw selector on top - for a basic linear layout?
  • 时间:2012-05-23 15:21:10
  •  标签:
  • android

我想用一个选择点点击状态来绘制一个简单的布局, 以绘制它的子上方的布局。 我认为这与 ListsView 中的“ 绘图选择OnTop ” 属性类似 。 例如布局 :

<LinearLayout
  android:background="@drawable/my_click_selector">
    <LinearLayout
      android:background="#F00" />
</LinearLayout>

---------------
|             |
| ----------- |
| ----------- |
|             |
---------------

因此在这里我们有一个父线性版式, 和一个有坚实背景颜色( 红色) 的内子。 当我单击父色时, 我选择器定义的资产变化的背景颜色, 但是由于该子子更接近 Z- 顺序中的用户, 它保持不变 。

是否有办法让选择者所选择的国家在所有儿童之上而不是在儿童之下划线?

谢谢 谢谢

问题回答

我面对这个问题, 我之前看着你的问题, 在这里,我做了什么 和工作完美:

您可以使用 FrameLayout 和roid:foreground 属性来完成您的任务

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:descendantFocusability="afterDescendants"
    android:duplicateParentState="true"
    android:focusable="true">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:descendantFocusability="beforeDescendants"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:foreground="@drawable/draw_on_top_selector">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#282828"
            android:paddingBottom="5dp">

            <ImageView
                android:layout_width="160dp"
                android:layout_height="90dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_gravity="center_vertical|center_horizontal"
                android:adjustViewBounds="true"
                android:contentDescription="@string/app_name"
                android:scaleType="centerCrop"
                android:src="@drawable/video_blank" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@id/episodeImage"
                android:layout_alignLeft="@id/episodeImage"
                android:background="@android:color/black"
                android:gravity="right"
                android:padding="2dp"
                android:textColor="#FFFFFF"
                android:textSize="11sp" />

        </RelativeLayout>
    </FrameLayout>
</LinearLayout>

rap_ on_top_ 选择器. xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/show_cell_background_selected" android:state_pressed="true"/>
    <item android:drawable="@drawable/show_cell_background"/>
</selector>

显示_ cell_ 背景_ 选择的. xml

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

    <item>
        <shape android:shape="rectangle" >
            <stroke
                android:width="4dp"
                android:color="#FFD900" >
            </stroke>

            <solid android:color="@android:color/transparent" />
        </shape>
    </item>

</layer-list>

显示_ cell_ 背景. xml

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item>
        <shape android:shape="rectangle" >
            <stroke
                android:width="2dp"
                android:color="#20000000" >
            </stroke>

            <solid android:color="@android:color/transparent" />
        </shape>
    </item>

</layer-list>

http://castorflex.github.io/blog/2013/07/17/adding-a-foreground-selector-to-a-view/"rel=“nofollow”>在任何视图上都写了一个关于绘制前景选择器的文章 。 它会让您避免嵌套布局 。

希望这能帮上忙

尝试使用 ForegroundLinearLayout https://gist.github.com/chrisbanes/9091754

您可以使用 < a href= > "https://github.com/baole/ foregroundView" rel = “ no follow” > ForegroundView 库





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签