首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >焦点表行不工作

焦点表行不工作
EN

Stack Overflow用户
提问于 2012-10-03 11:46:50
回答 1查看 812关注 0票数 0

我有一个TableLayout,我希望内部的元素(每个表行都有一个文本视图)集中在ontouch上。我将每个元素的可聚焦属性设置为true,但它不起作用!

这是xml:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="right" >


<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:background="#444444"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="bottom"
    android:orientation="vertical" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:focusable="true"
        android:focusableInTouchMode="true" >

        <requestFocus />


        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#993399"
            android:clickable="true"
            android:focusable="true"
            android:focusableInTouchMode="true" >





            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:clickable="true"
                android:editable="false"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="right"
                android:text="Zein"
                android:textAppearance="?android:attr/textAppearanceMedium" />

        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="Home"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="About us"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#00FF00"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="right"
                android:text="Students"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow5"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView5"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="left"
                android:text="Course Scheduele"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow6"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView6"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="left"
                android:text="Exam Scheduele"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow7"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView7"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="Exam Grades"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow8"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView8"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="Course Grades"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow9"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView9"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="GPA"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow10"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView10"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="Drop &amp; Add"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow11"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView11"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="Petition Enquiry"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow12"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView12"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#00FFFF"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="right"
                android:text="University Services"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow13"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView13"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="Petition Enquiry"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow14"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#D60024"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView14"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="right"
                android:text="Employees"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow15"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView15"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="Petition Enquiry"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow16"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#009933"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView16"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:gravity="right"
                android:text="My Account"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow17"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:focusable="true"
            android:focusableInTouchMode="true" >

            <TextView
                android:id="@+id/textView17"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:text="Petition Enquiry"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>
    </TableLayout>
</LinearLayout>

我希望每个元素都能在用户触摸到它时成为焦点,知道为什么它不在这里工作吗?

drawable/table.xml

更新:

代码语言:javascript
运行
复制
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true"
           android:color="#993399" /> <!-- pressed -->
     <item android:state_focused="true"
           android:color="#993399" /> <!-- focused -->
     <item android:color="#222222" /> <!-- default -->

</selector>

这就是我如何在我的main.xml中引用它

代码语言:javascript
运行
复制
 android:src="@drawable/table1"

还是什么都没发生

EN

回答 1

Stack Overflow用户

发布于 2012-10-03 12:34:49

为listview项创建选择器,并设置其参数,例如:

代码语言:javascript
运行
复制
<item android:drawable="@drawable/but" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/butpressed" android:state_pressed="true"/>
<item android:drawable="@drawable/butpressed" android:state_pressed="false" android:state_selected="true"/>

在本例中,我更改了图片,但您可以设置任何其他参数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12707845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档