【问题标题】:how to set background of an image and a text /image over it in android如何在android中设置图像的背景和文本/图像
【发布时间】:2015-03-26 21:51:51
【问题描述】:

我是 android 新手,我在网上制作了 psd 到 pngs,现在我有各种 pngs。 我需要设计 UI,其中有一个背景图像和一个菜单图标图像

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/shape"
    android:background="@drawable/shapes"
    android:text="Button" />

我尝试将它们设置为背景,但我有两个图像如何做到这一点。还可以在其上设置文本图像。 我的 psd 到 png 链接是 here 我有多个图像。

我在中心有this 图像this 在左侧和上方必须设置this

【问题讨论】:

  • 您能解释一下吗?标记 png 的区域,即您要尝试的区域。
  • 不工作:(我已经这样做了。我有两张图片在我的图片中寻找它写欢迎菜单的地方。第一个是背景第二个是图像图标(菜单)
  • 这是我在这里提到的文件:s7.postimg.org/dj2cjoil7/pngs2.png
  • 所以你只想做那部分?
  • 你能用简单的话告诉我们你想做什么吗?

标签: android android-layout layout


【解决方案1】:

好的,试试这个

 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#5A99A8" >

        <ImageView
            android:id="@+id/menu"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="#40000000"
            android:padding="12dp"
            android:src="@drawable/your_menu_image" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/sett"
            android:layout_toRightOf="@+id/menu"
            android:gravity="center"
            android:text="WELCOME MENU"
            android:textColor="#FFF" />

        <ImageView
            android:id="@+id/sett"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_alignParentRight="true"
            android:background="#40000000"
            android:padding="12dp"
            android:src="@drawable/your_settings_image" />
    </RelativeLayout>

并且使用颜色而不是图像来获得这种类型的标题栏

【讨论】:

  • 你有在 xmls 中为 android 制作经典 UI 的链接吗?因为我在 youtube 上搜索了很多,但找不到。我需要使用我的 psds。虽然这很有效,但有些事情像音量滑块作为 png 和其他东西。
【解决方案2】:

这不是一个好的解决方案

<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/shape"
        android:drawableLeft="@drawable/abc"
        android:drawableRight="@drawable/def"
        android:background="@drawable/shapes"
        android:text="Button" />

【讨论】:

    猜你喜欢
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    • 2022-07-11
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    相关资源
    最近更新 更多