【问题标题】:How to set an Image in background such that it will be see in other part of cardview?如何在背景中设置图像以便在卡片视图的其他部分中看到?
【发布时间】:2017-03-18 10:30:58
【问题描述】:

我是 android 应用程序开发的新手。我正在 android 中做一个项目。我已经在背景中设置了一张图片,以便在 cardview 的其他部分看到。如果有人知道,请分享你的答案。我的 XML 代码如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:background="#FFFFFF"
    android:src="@drawable/images1"/> 
<android.support.v7.widget.CardView
    android:orientation = "vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/RateMe"
            android:text="Rate your experience?"
            android:layout_marginLeft="40dp"
            android:background="#FFFFFF"
            android:textAppearance="@android:style/TextAppearance.Large"/>
        <RatingBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/ratingBar"
            android:numStars="5"
            android:layout_marginLeft="40dp"
            android:stepSize="0.1" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Cleaniness"
            android:text="How was cleaniness?"
            android:layout_marginLeft="40dp"
            android:textAppearance="@android:style/TextAppearance.Large"/>
        <RatingBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/RateClean"
            android:numStars="5"
            android:layout_marginLeft="40dp"
            android:stepSize="0.1" />
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Comment"
            android:layout_marginLeft="40dp"
            android:hint="please enter comment here" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/bttn"
            android:hint="Submit"
            android:layout_marginLeft="40dp"
            android:layout_gravity="center" />
        </LinearLayout>
    </android.support.v7.widget.CardView></LinearLayout>

【问题讨论】:

标签: android xml android-layout android-cardview


【解决方案1】:

你为什么不尝试让你的 LinearLayout 成为你想要的颜色,并且 cardView 具有透明背景。使用您的代码,您应该有这样的东西

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/bg">

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:orientation = "vertical"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    card_view:cardCornerRadius="5dp"
    card_view:cardElevation="5dp"
    card_view:cardBackgroundColor="#55FFFFFF">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/RateMe"
            android:text="Rate your experience?"
            android:layout_marginLeft="40dp"
            android:textAppearance="@android:style/TextAppearance.Large"/>
        <RatingBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/ratingBar"
            android:numStars="5"
            android:layout_marginLeft="40dp"
            android:stepSize="0.1" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Cleaniness"
            android:text="How was cleaniness?"
            android:layout_marginLeft="40dp"
            android:textAppearance="@android:style/TextAppearance.Large"/>
        <RatingBar
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/RateClean"
            android:numStars="5"
            android:layout_marginLeft="40dp"
            android:stepSize="0.1" />
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Comment"
            android:layout_marginLeft="40dp"
            android:hint="please enter comment here" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/bttn"
            android:hint="Submit"
            android:layout_marginLeft="40dp"
            android:layout_gravity="center" />
    </LinearLayout>
</android.support.v7.widget.CardView>

【讨论】:

  • 当我在背景中添加图像时,它会与卡片视图重叠。我想要 UI 以便在卡片视图的其他部分中看到部分图像。
  • @Dipu Kumar 我已编辑代码以使用 FrameLayout 并更改 CardView 背景的 alpha。也许我没有得到你想要的。如果此代码不能解决您的问题,请添加注释并举例说明您想要的内容。谢谢
【解决方案2】:

如果您想让您的活动透明,请查看此答案 - How do I create a transparent Activity on Android?

【讨论】:

    猜你喜欢
    • 2020-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多