Android的列表视图行的利润 [英] Android List View Row margins

查看:98
本文介绍了Android的列表视图行的利润的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个简单的列表视图中,有一些填充的每一行。

I was trying to create a simple list view that has some padding for each row.

我做了一个非常简单的方法,但我不知道这是否是正确的™的方式来做到这一点。

I did it in a really simple way, but I'm not sure if it is the right™ way to do it.

这是我得到了什么(code是如下图)。正如你所看到的,当你点击一排,它完全突出,我想(如果可能的话),以突出显示只有里面的视图(带有灰色背景,这是一个TextView)

This is what I got (code is below). As you can see when you tap a row, it is fully highlighted, and I want (if possible) to highlight only the view inside it (the one with the gray background, that is a TextView)

这是在code的活动布局:

this is the code for the Activity layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:divider="@null"
        android:dividerHeight="0dp" />

    <TextView
        android:id="@android:id/empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_events" />

</LinearLayout>

这就是列表项的布局code:

and this is the code of the list item layout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:padding="10dp">

    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/text1"
        android:layout_width="fill_parent"
        android:layout_height="30dp"
        android:background="#ccc"
        android:text="placeholder" />

</FrameLayout>

感谢您的答复!

Thanks for any reply!

PS。我没有上传的活动,这是一个简单的ListActivity。

PS. I didn't upload the Activity, it is a simple ListActivity.

更新

解决(感谢豪尔赫·阿吉拉尔)。新的code是这样的:

Resolved (thanks to Jorge Aguilar). The new code is this:

列表项:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:padding="10dp">

    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/text1"
        android:layout_width="fill_parent"
        android:layout_height="30dp"
        android:background="@drawable/event_focused"
        android:text="placeholder" />

</FrameLayout>

事件集中文件(这是在绘制目录):

Event focused file (which is in the drawable directory):

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:drawable="@android:color/black" /> <!-- pressed -->
    <item android:state_focused="true"
          android:drawable="@android:color/darker_gray" /> <!-- focused -->
    <item android:state_hovered="true"
          android:drawable="@android:color/darker_gray" /> <!-- hovered -->
    <item android:drawable="@android:color/darker_gray" /> <!-- default -->
</selector>

我还添加了这一点:

I also added this:

android:listSelector="@android:color/transparent"

我的ListView:)

to my ListView :)

推荐答案

那么你可以在onitemselected方法添加一些code找到TextView中通过ID或类似的东西,然后改变背景颜色。或者是不同的东西,你想要什么?

Well you can add on the onitemselected method some code to find the textview by id or something similar and then change the background color. or is something different what you want ?

更新:

如果您需要将其从XML文件中的变化,也许这的帖子 可以帮你实现它。只是跳到最后发表的帖子,希望你会发现你的答案在那里。

If you need to change it from within the xml file, maybe this post can help you achieve it. just skip to the last post and hopefully you will find your answer there.

这篇关于Android的列表视图行的利润的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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