在LinearLayout上设置背景图像

时间:2012-05-28 16:16:35

标签: android

有没有办法将背景图像添加到LinearLayout,所以按钮控件会被绘制到它上面?我试图看看有没有办法让位图作为LinearLayout的背景,但找不到办法。

2 个答案:

答案 0 :(得分:10)

您可以使用xml-Tag android:background="@drawable/yourbackground"或通过代码setBackgroundResource(int)

设置它

答案 1 :(得分:0)

使用框架布局并放置图像视图,然后像这样放置线性布局:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="centerCrop"
    app:srcCompat="@drawable/chrysanthemum"
    android:contentDescription="@string/todo" />

<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/quan"
        android:layout_width="107dp"
        android:layout_height="56dp"
        android:gravity="center"
        android:text="quantity"
        android:textAllCaps="true"
        android:textColor="#000000" />

</LinearLayout>
</FrameLayout>
相关问题