有什么方法可以将 Items 放在 Android 中的 ImageView 中
Is there any possible way to put Items inside of ImageView in Android
我正在制作一个 App
,它有两个 ImageView
其中一个用于背景,使用 Picasso 加载具有模糊效果的图像,第二个显示正常的海报形状,我想知道如何将一些内容(例如 textView
放在我的模糊图像下面的图层上?
这是我的布局和代码的图片:
我想把那些 IMDB
、观看和想要 TextViews
的计数放在第二个 ImageView
上,现在是 Blur,我该怎么做?
<RelativeLayout
android:id="@+id/pallet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/transparent"
android:transitionName="profile">
<ImageView
android:id="@+id/blur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:transitionName="profile">
</ImageView>
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:elevation="0dp"
app:cardCornerRadius="10dp"
android:transitionName="profile">
<ImageView
android:id="@+id/posterImage"
android:layout_width="match_parent"
android:layout_height="400dp"
android:scaleType="fitXY"
android:transitionName="profile"
android:layout_gravity="center"/>
<ImageButton
android:id="@+id/playTrailer"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:baselineAlignBottom="true"
android:layout_gravity="bottom|end"
android:layout_marginRight="35dp"
android:layout_marginBottom="35dp"
android:background="@drawable/play_circle"
android:elevation="10dp"
android:scaleType="fitCenter"/>
</android.support.v7.widget.CardView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/cardView"
android:background="@color/transparent">
<TextView
android:id="@+id/movieTitle"
style="@style/movieTitleFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark"
android:textSize="22dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<TextView
android:id="@+id/watchNum"
style="@style/movieTitleFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="341"
android:textAlignment="viewStart"
android:textSize="26dp" />
<TextView
android:id="@+id/wantNum"
style="@style/movieTitleFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="880"
android:textAlignment="center"
android:textSize="26dp" />
<TextView
android:id="@+id/imdbNum"
style="@style/movieTitleFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:textAlignment="viewEnd"
android:textSize="26dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/watchNumtxt"
style="@style/subText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Watched"
android:textAlignment="viewStart"
android:textColor="@color/cardview_dark_background"
android:textSize="18dp" />
<TextView
android:id="@+id/wantNumtxt"
style="@style/subText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Want"
android:textAlignment="center"
android:textSize="18dp" />
<TextView
android:id="@+id/imdbNumtxt"
style="@style/subText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="IMDB"
android:textAlignment="viewEnd"
android:textColor="@color/cardview_dark_background"
android:textSize="18dp" />
</RelativeLayout>
而且无论如何我可以给下面模糊图像的半径来显示白色的角?它现在是白色的只是因为底部的海报是白色的,我可以用picasso
吗?
好的,试试这样的方法,我简化只是为了方便,您应该只了解逻辑,然后正确放置您的项目。
你现在的问题是你有一个 Layout
叠加模糊和 CardView
但是你有另一个用于信息。
您应该将它们全部放在相同的相对布局中以允许叠加或创建子元素。
<RelativeLayout> <!-- Contains background (blur + infos) and CardView -->
<RelativeLayout> <!-- Contains blur image and text informations (Not even necessarily needed depends on you) -->
<ImageView
android:id="@+id/blur" />
<YourInformationsView/>
</RelativeLayout>
<android.support.v7.widget.CardView />
</RelativeLayout>
SO 上已经有很多此类问题:例如 This or this one。也尝试研究这些。
为什么不直接将 imageView 和 textView 添加到 frameLayout 中,并根据 imageView 的图像为 frameLayout 设置背景。
<RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="@+id/blur" .../>
<TextView ... />
</FrameLayout>
<android.support.v7.widget.CardView .../>
</RelativeLayout>
不要考虑如何向您的 ImageView
添加内容,请考虑如何在 ImageView
上方您需要的地方添加内容。
<ImageView
android:id="@+id/blur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:transitionName="profile">
</ImageView>
变成类似
的东西
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_alignParentTop="true"
...your ImageView/>
<View
this is your blurred view
android:layout_width="match_parent"
android:layout_height="match_parent"
do something to blur this />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
your textviews...
</RelativeLayout>
当然,如果你把 match_parent
放进去,顶部的 RelativeLayout
就不能再是 wrap_content
高度了,但是你的图像看起来不是那样的。它甚至看起来像 ImageView
上方但文本下方的模糊层。它看起来不像是 ImageView
那是模糊的,而是它上面有一个模糊层。
我正在制作一个 App
,它有两个 ImageView
其中一个用于背景,使用 Picasso 加载具有模糊效果的图像,第二个显示正常的海报形状,我想知道如何将一些内容(例如 textView
放在我的模糊图像下面的图层上?
这是我的布局和代码的图片:
我想把那些 IMDB
、观看和想要 TextViews
的计数放在第二个 ImageView
上,现在是 Blur,我该怎么做?
<RelativeLayout
android:id="@+id/pallet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/transparent"
android:transitionName="profile">
<ImageView
android:id="@+id/blur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:transitionName="profile">
</ImageView>
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:elevation="0dp"
app:cardCornerRadius="10dp"
android:transitionName="profile">
<ImageView
android:id="@+id/posterImage"
android:layout_width="match_parent"
android:layout_height="400dp"
android:scaleType="fitXY"
android:transitionName="profile"
android:layout_gravity="center"/>
<ImageButton
android:id="@+id/playTrailer"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:baselineAlignBottom="true"
android:layout_gravity="bottom|end"
android:layout_marginRight="35dp"
android:layout_marginBottom="35dp"
android:background="@drawable/play_circle"
android:elevation="10dp"
android:scaleType="fitCenter"/>
</android.support.v7.widget.CardView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/cardView"
android:background="@color/transparent">
<TextView
android:id="@+id/movieTitle"
style="@style/movieTitleFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark"
android:textSize="22dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<TextView
android:id="@+id/watchNum"
style="@style/movieTitleFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="341"
android:textAlignment="viewStart"
android:textSize="26dp" />
<TextView
android:id="@+id/wantNum"
style="@style/movieTitleFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="880"
android:textAlignment="center"
android:textSize="26dp" />
<TextView
android:id="@+id/imdbNum"
style="@style/movieTitleFont"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="25dp"
android:textAlignment="viewEnd"
android:textSize="26dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/watchNumtxt"
style="@style/subText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:text="Watched"
android:textAlignment="viewStart"
android:textColor="@color/cardview_dark_background"
android:textSize="18dp" />
<TextView
android:id="@+id/wantNumtxt"
style="@style/subText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Want"
android:textAlignment="center"
android:textSize="18dp" />
<TextView
android:id="@+id/imdbNumtxt"
style="@style/subText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:text="IMDB"
android:textAlignment="viewEnd"
android:textColor="@color/cardview_dark_background"
android:textSize="18dp" />
</RelativeLayout>
而且无论如何我可以给下面模糊图像的半径来显示白色的角?它现在是白色的只是因为底部的海报是白色的,我可以用picasso
吗?
好的,试试这样的方法,我简化只是为了方便,您应该只了解逻辑,然后正确放置您的项目。
你现在的问题是你有一个 Layout
叠加模糊和 CardView
但是你有另一个用于信息。
您应该将它们全部放在相同的相对布局中以允许叠加或创建子元素。
<RelativeLayout> <!-- Contains background (blur + infos) and CardView -->
<RelativeLayout> <!-- Contains blur image and text informations (Not even necessarily needed depends on you) -->
<ImageView
android:id="@+id/blur" />
<YourInformationsView/>
</RelativeLayout>
<android.support.v7.widget.CardView />
</RelativeLayout>
SO 上已经有很多此类问题:例如 This or this one。也尝试研究这些。
为什么不直接将 imageView 和 textView 添加到 frameLayout 中,并根据 imageView 的图像为 frameLayout 设置背景。
<RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="@+id/blur" .../>
<TextView ... />
</FrameLayout>
<android.support.v7.widget.CardView .../>
</RelativeLayout>
不要考虑如何向您的 ImageView
添加内容,请考虑如何在 ImageView
上方您需要的地方添加内容。
<ImageView
android:id="@+id/blur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:transitionName="profile">
</ImageView>
变成类似
的东西<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_alignParentTop="true"
...your ImageView/>
<View
this is your blurred view
android:layout_width="match_parent"
android:layout_height="match_parent"
do something to blur this />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
your textviews...
</RelativeLayout>
当然,如果你把 match_parent
放进去,顶部的 RelativeLayout
就不能再是 wrap_content
高度了,但是你的图像看起来不是那样的。它甚至看起来像 ImageView
上方但文本下方的模糊层。它看起来不像是 ImageView
那是模糊的,而是它上面有一个模糊层。