轨迹球在我的相对布局中不起作用

发布于 2024-11-16 12:44:00 字数 8655 浏览 6 评论 0原文

这是我的布局 xml。 我正在使用自定义背景。我在这段代码下面附加了 xml。 现在我的问题是当我使用轨迹球时我无法将注意力集中在按钮上。请帮助我..

settings.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" android:background="#002288">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/root"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:isScrollContainer="true"
        android:fitsSystemWindows="true"
        android:gravity="top">
        <RelativeLayout android:id="@+id/RelativeLayout01" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top">
            <TextView android:id="@+id/textView1"
                android:layout_width="fill_parent"
                android:layout_alignParentTop="true"
                android:paddingTop="6dp"
                android:paddingLeft="36dp"
                android:background="@drawable/bar_plain"
                android:layout_alignParentRight="true"
                android:layout_height="30dp"
                android:text="Settings"
                android:textColor="#FFFFFF">
            </TextView>
            <ImageView
                android:id="@+id/ImageView01"
                android:isScrollContainer="true"
                android:layout_alignParentTop="true" 
                android:layout_height="30dp"  
                android:src="@drawable/appicon"
                android:scaleType="fitStart"
                android:layout_width="30dp">
            </ImageView>
        </RelativeLayout>
        <ScrollView
            xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
            android:layout_below="@+id/textView1">
            <RelativeLayout
                android:id="@+id/relativeLayout1"
                android:layout_below="@+id/textView1"
                android:layout_width="fill_parent"
                android:paddingTop="10dp"
                android:layout_height="fill_parent"
                android:layout_centerVertical="true"
                android:background="#002288">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/imageView1"
                    android:layout_alignParentLeft="true"
                    android:src="@drawable/icon">
                </ImageView>
                <Button
                    android:id="@+id/button1"
                    android:layout_toRightOf="@+id/imageView1"
                    android:height="50dp"
                    android:layout_width="200dp"
                    android:layout_height="50dp"
                    android:textColor="#ffffff"
                    android:gravity="left|center_vertical"
                    android:textSize="20dp"
                    android:background="@drawable/button_selector"
                    android:text="@string/Display"
                    android:focusable="true">
                </Button>
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/imageView2"
                    android:layout_alignParentLeft="true"
                    android:src="@drawable/icon"
                    android:layout_below="@id/button1"
                    android:layout_marginTop="20dp">
                </ImageView>
                <Button
                    android:id="@+id/button2"
                    android:layout_toRightOf="@+id/imageView2"
                    android:height="50dp"
                    android:layout_width="200dp"
                    android:layout_height="50dp"
                    android:textColor="#ffffff"
                    android:gravity="left|center_vertical"
                    android:textSize="20dp"
                    android:layout_below="@id/button1"
                    android:layout_marginTop="20dp"
                    android:background="@drawable/button_selector"
                    android:text="@string/compose"
                    android:focusable="true">
                </Button>
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/imageView3"
                    android:layout_alignParentLeft="true"
                    android:src="@drawable/icon"
                    android:layout_below="@id/button2"
                    android:layout_marginTop="20dp">
                </ImageView>
                <Button
                    android:id="@+id/button3"
                    android:layout_toRightOf="@+id/imageView3"
                    android:height="50dp"
                    android:layout_width="200dp"
                    android:layout_height="50dp"
                    android:textColor="#ffffff"
                    android:gravity="left|center_vertical" android:textSize="20dp" android:layout_below="@id/button2" android:layout_marginTop="20dp" android:background="@drawable/button_selector" android:text="@string/Message" android:focusable="true">
                </Button>
                <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView4" android:layout_alignParentLeft="true" android:src="@drawable/icon" android:layout_below="@id/button3" android:layout_marginTop="20dp">
                </ImageView>
                <Button android:id="@+id/button4" android:layout_toRightOf="@+id/imageView2" android:height="50dp" android:layout_width="200dp" android:layout_height="50dp" android:textColor="#ffffff" android:gravity="left|center_vertical" android:textSize="20dp" android:layout_below="@id/button3" android:layout_marginTop="20dp" android:background="@drawable/button_selector" android:text="@string/New_SMS" android:focusable="true">
                </Button>
                <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView5" android:layout_alignParentLeft="true" android:src="@drawable/icon" android:layout_below="@id/button4" android:layout_marginTop="20dp">
                </ImageView>
                <Button android:id="@+id/button5" android:layout_toRightOf="@+id/imageView2" android:height="50dp" android:layout_width="200dp" android:layout_height="50dp" android:textColor="#ffffff" android:gravity="left|center_vertical" android:textSize="20dp" android:layout_below="@id/button4" android:layout_marginTop="20dp" android:background="@drawable/button_selector" android:text="@string/Privacy" android:focusable="true">
                </Button>
            </RelativeLayout>
        </ScrollView>
    </LinearLayout>
</ScrollView>

button_sellector.xml

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

  <!-- pressed -->
  <item android:state_pressed="true" >
    <shape>
      <stroke android:width="1px" android:color="#444"  />
   <TextColor  android:textColor="#000000"/>
   <solid android:color="#FFEE33" />
    </shape>
  </item>
  <!-- focused -->
  <item android:state_focused="true" >
    <shape>
      <stroke android:width="1px" android:color="#444" />
      <TextColor  android:textColor="#000000"/>
      <solid android:color="#FFEE33"/>
    </shape>
  </item>

  <!-- default -->
  <item>
    <shape>
      <solid android:color="#002288"/>
      <stroke android:width="1px" android:color="#002288" />
    </shape>
  </item>

  <!-- -Scrolled -->
  <item android:state_selected ="true" >
    <shape>
      <stroke android:width="1px" android:color="#444" />
      <TextColor  android:textColor="#000000"/>
      <solid android:color="#FFEE33"/>
    </shape>
  </item>
</selector>

Here is my layout xml.
I am using custom background. xml which i attached below this code.
now my problem is iam not getting focus on button when i use trackball.please help me..

settings.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" android:background="#002288">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/root"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:isScrollContainer="true"
        android:fitsSystemWindows="true"
        android:gravity="top">
        <RelativeLayout android:id="@+id/RelativeLayout01" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top">
            <TextView android:id="@+id/textView1"
                android:layout_width="fill_parent"
                android:layout_alignParentTop="true"
                android:paddingTop="6dp"
                android:paddingLeft="36dp"
                android:background="@drawable/bar_plain"
                android:layout_alignParentRight="true"
                android:layout_height="30dp"
                android:text="Settings"
                android:textColor="#FFFFFF">
            </TextView>
            <ImageView
                android:id="@+id/ImageView01"
                android:isScrollContainer="true"
                android:layout_alignParentTop="true" 
                android:layout_height="30dp"  
                android:src="@drawable/appicon"
                android:scaleType="fitStart"
                android:layout_width="30dp">
            </ImageView>
        </RelativeLayout>
        <ScrollView
            xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
            android:layout_below="@+id/textView1">
            <RelativeLayout
                android:id="@+id/relativeLayout1"
                android:layout_below="@+id/textView1"
                android:layout_width="fill_parent"
                android:paddingTop="10dp"
                android:layout_height="fill_parent"
                android:layout_centerVertical="true"
                android:background="#002288">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/imageView1"
                    android:layout_alignParentLeft="true"
                    android:src="@drawable/icon">
                </ImageView>
                <Button
                    android:id="@+id/button1"
                    android:layout_toRightOf="@+id/imageView1"
                    android:height="50dp"
                    android:layout_width="200dp"
                    android:layout_height="50dp"
                    android:textColor="#ffffff"
                    android:gravity="left|center_vertical"
                    android:textSize="20dp"
                    android:background="@drawable/button_selector"
                    android:text="@string/Display"
                    android:focusable="true">
                </Button>
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/imageView2"
                    android:layout_alignParentLeft="true"
                    android:src="@drawable/icon"
                    android:layout_below="@id/button1"
                    android:layout_marginTop="20dp">
                </ImageView>
                <Button
                    android:id="@+id/button2"
                    android:layout_toRightOf="@+id/imageView2"
                    android:height="50dp"
                    android:layout_width="200dp"
                    android:layout_height="50dp"
                    android:textColor="#ffffff"
                    android:gravity="left|center_vertical"
                    android:textSize="20dp"
                    android:layout_below="@id/button1"
                    android:layout_marginTop="20dp"
                    android:background="@drawable/button_selector"
                    android:text="@string/compose"
                    android:focusable="true">
                </Button>
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/imageView3"
                    android:layout_alignParentLeft="true"
                    android:src="@drawable/icon"
                    android:layout_below="@id/button2"
                    android:layout_marginTop="20dp">
                </ImageView>
                <Button
                    android:id="@+id/button3"
                    android:layout_toRightOf="@+id/imageView3"
                    android:height="50dp"
                    android:layout_width="200dp"
                    android:layout_height="50dp"
                    android:textColor="#ffffff"
                    android:gravity="left|center_vertical" android:textSize="20dp" android:layout_below="@id/button2" android:layout_marginTop="20dp" android:background="@drawable/button_selector" android:text="@string/Message" android:focusable="true">
                </Button>
                <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView4" android:layout_alignParentLeft="true" android:src="@drawable/icon" android:layout_below="@id/button3" android:layout_marginTop="20dp">
                </ImageView>
                <Button android:id="@+id/button4" android:layout_toRightOf="@+id/imageView2" android:height="50dp" android:layout_width="200dp" android:layout_height="50dp" android:textColor="#ffffff" android:gravity="left|center_vertical" android:textSize="20dp" android:layout_below="@id/button3" android:layout_marginTop="20dp" android:background="@drawable/button_selector" android:text="@string/New_SMS" android:focusable="true">
                </Button>
                <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView5" android:layout_alignParentLeft="true" android:src="@drawable/icon" android:layout_below="@id/button4" android:layout_marginTop="20dp">
                </ImageView>
                <Button android:id="@+id/button5" android:layout_toRightOf="@+id/imageView2" android:height="50dp" android:layout_width="200dp" android:layout_height="50dp" android:textColor="#ffffff" android:gravity="left|center_vertical" android:textSize="20dp" android:layout_below="@id/button4" android:layout_marginTop="20dp" android:background="@drawable/button_selector" android:text="@string/Privacy" android:focusable="true">
                </Button>
            </RelativeLayout>
        </ScrollView>
    </LinearLayout>
</ScrollView>

button_sellector.xml

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

  <!-- pressed -->
  <item android:state_pressed="true" >
    <shape>
      <stroke android:width="1px" android:color="#444"  />
   <TextColor  android:textColor="#000000"/>
   <solid android:color="#FFEE33" />
    </shape>
  </item>
  <!-- focused -->
  <item android:state_focused="true" >
    <shape>
      <stroke android:width="1px" android:color="#444" />
      <TextColor  android:textColor="#000000"/>
      <solid android:color="#FFEE33"/>
    </shape>
  </item>

  <!-- default -->
  <item>
    <shape>
      <solid android:color="#002288"/>
      <stroke android:width="1px" android:color="#002288" />
    </shape>
  </item>

  <!-- -Scrolled -->
  <item android:state_selected ="true" >
    <shape>
      <stroke android:width="1px" android:color="#444" />
      <TextColor  android:textColor="#000000"/>
      <solid android:color="#FFEE33"/>
    </shape>
  </item>
</selector>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮光沉寂 2024-11-23 12:44:00

您的代码工作正常。我已经在我的模拟器中测试过了。

Your code is working correctly. I have tested it in my emulator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文