【问题标题】:How to create a button on top of ImageView and align it to the bottom of the screen?如何在 ImageView 顶部创建一个按钮并将其与屏幕底部对齐?
【发布时间】:2013-08-14 13:05:01
【问题描述】:

我想使用我的xml 文件在ImageView 上添加一个按钮。当我运行此代码时,该按钮出现在屏幕左侧的其他按钮之上。

有没有人知道如何在ImageView 的顶部但在屏幕底部有一个按钮。

到目前为止,我有以下内容:

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

    <ImageView
        android:id="@+id/filter_image_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_toRightOf="@id/filter_linear_layout" />

//this is the button I want to have on top of the ImageView
    <Button
        android:id="@+id/display_RGB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/button_blue_red_transluscent"
        android:text="@string/display_RGB"
        android:textColor="@android:color/white" />

</RelativeLayout>

只要它在屏幕底部的某个位置,但在中心,不要太挑剔。

【问题讨论】:

标签: android xml button imageview android-linearlayout


【解决方案1】:

你可以把它们放在自己的RelativeLayout中,然后你可以很容易地操纵按钮相对于ImageView的位置。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_toRightOf="@id/filter_linear_layout" >

    <ImageView
        android:id="@+id/filter_image_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        />

    <Button
        android:id="@+id/display_RGB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_blue_red_transluscent"
        android:text="@string/display_RGB"
        android:textColor="@android:color/white"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/filter_image_view"
         />
</RelativeLayout>

如果这不是您想要的,您需要发布一张示例图片,说明它当前的外观以及您希望它的外观。

[编辑] 编辑 XML 布局。如果您希望 ImageView 水平居中,请将其添加到 ImageView:

    android:layout_centerHorizontal="true"

您可能希望通过将其添加到 Button 在 ImageView 和 Button 之间添加一些间距:

    android:layout_marginTop="8dp"

【讨论】:

  • +1 - 这就是东西,只需要放一张图片来告诉你我的意思是在imageview上的位置。请稍等
  • 你去。图片已上传
【解决方案2】:

试试这个。

<Button
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:padding="16dip"
        android:text="hi"
        android:textColor="@color/black"
         />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多