【问题标题】:Clickable relative layout可点击的相对布局
【发布时间】:2011-10-22 20:32:40
【问题描述】:

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

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

【问题讨论】:

    标签: android layout user-interface android-layout outline


    【解决方案1】:

    如果您只想在 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>
    

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

    这就是你要找的吗?

    【讨论】:

      【解决方案2】:

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

      public void methodName(View v){
      
      }
      

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

      【讨论】:

      • 对不起,也许我应该更清楚。我已经实现了可点击性,我只想在布局本身周围画一个轮廓(例如,一个框),以使其“显示”为一个按钮。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多