0

我有一个带有文本视图的可点击相对布局,我想围绕它创建一个大纲,以允许用户意识到它是可点击的,但我不知道如何去做。任何帮助,将不胜感激。

编辑:我已经实现了可点击性,也就是说,我已经能够点击它并让它做一些事情。我只想在布局本身周围画一个框来表明它是可点击的。

4

2 回答 2

3

如果你只是想在 RelativeLayout 周围画一个框架,你可以很简单地做到这一点。

  1. 将您的 RelativeLayout 放在 FrameLayout 中。
  2. 将 FrameLayout 的背景设置为您希望框为任何颜色。
  3. 将 FrameLayout 的填充设置为框的所需宽度

所以你的 XML 看起来像这样:

<FrameLayout
android:id="@+id/colored_frame"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="10dip"
android:background="#FF0055CC">

    <RelativeLayout
    android:id="@+id/your_relative_layout"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:padding="10dp"
    android:background="#FF000000">

        <TextView
        android:id="@+id/some_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Relative Layout"
        android:textSize="40sp"
        />

        <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/some_text"
        android:text="..."
        android:textSize="30sp"
        />


    </RelativeLayout>

</FrameeLayout>

现在您的相对布局周围有一个框(在本例中为蓝色)

带框架的相对布局

那是你要找的吗?

于 2011-08-09T21:14:30.487 回答
0

视图有一个 xml 属性名称 android:onClick="methodName"。LinearLayout,RelativeLayout继承View。您可以将方法名称设置为此属性。您的方法必须具有以下格式:

public void methodName(View v){

}

Action 方法必须是 public、void 并且有一个参数类型 View。将此方法放在您的上下文(活动)上。祝你好运 :)

于 2011-08-09T02:40:16.117 回答