2017-07-31 71 views
0

我有这个rec​​yclerview,背景是用图像制作的。我在肖像和风景中有这两种情况。如何用新的imageview或具有相同颜色的东西填充空白处?用两个图像查看横向模式下的宽度

portraitlandscape

,这是我的xml:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal"> 

<ImageView 
    android:id="@+id/home_imageview_superbackground" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentStart="true" /> 

<ImageView 
    android:id="@+id/home_imageview_background" 
    android:contentDescription="Background image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:adjustViewBounds="true" 
    android:layout_alignParentEnd="true" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true"> 

    <TextView 
     android:id="@+id/content" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:fontFamily="casual" 
     android:paddingBottom="10dp" 
     android:paddingStart="5dp" 
     android:paddingTop="10dp" 
     android:textAppearance="?attr/textAppearanceListItem" 
     android:textColor="@android:color/white" 
     android:textSize="40sp" /> 
</RelativeLayout> 

试了几种方法,但我只是不能够使这项工作。 @ + id/home_imageview_superbackground这是我想放在每个背景图像视图的左侧以填充景观中的空间的imageview。感谢您的帮助。

回答

0
<ImageView 
android:layout_width="match_parent" 
.... /> 

您也可以使用scaleType属性

+0

对不起队友,但你甚至没有尝试帮我:) – Weizen

+0

对不起。创建景观变化布局。 –

1

请试试这个

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/home_imageview_superbackground" 
     android:layout_width="match_parent" 
     android:src="@mipmap/ic_launcher" 
     android:scaleType="fitXY" 
     android:layout_height="wrap_content" /> 

    <ImageView 
     android:id="@+id/home_imageview_background" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@mipmap/ic_launcher" 
     android:scaleType="fitXY" 
     android:contentDescription="Background image" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true"> 

     <TextView 
      android:id="@+id/content" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:fontFamily="casual" 
      android:paddingBottom="10dp" 
      android:paddingTop="10dp" 
      android:textAppearance="?attr/textAppearanceListItem" 
      android:textColor="@android:color/white" 
      android:textSize="40sp" /> 
    </RelativeLayout> 
</RelativeLayout> 

您也可以使用Android:scaleType = “centerCrop”。

希望这将有助于you..If还是你面对问题,请告诉我...

0

首先,FILL_PARENT是次前弃用,你应该使用match_parent来代替。然后,当您使用ImagesView来定义图像在屏幕上的显示方式时,还需要使用scaleType。在你的情况下,使用scaleType =“fitXY”解决你的问题。

如何使你的代码应该是:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="wrap_content"> 

<ImageView 
    android:id="@+id/home_imageview_superbackground" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:scaleType="fitXY" 
    android:layout_alignParentStart="true" /> 

<ImageView 
    android:id="@+id/home_imageview_background" 
    android:contentDescription="Background image" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scaleType="fitXY" 
    android:adjustViewBounds="true" 
    android:layout_alignParentEnd="true" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true"> 

    <TextView 
     android:id="@+id/content" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:fontFamily="casual" 
     android:paddingBottom="10dp" 
     android:paddingStart="5dp" 
     android:paddingTop="10dp" 
     android:textAppearance="?attr/textAppearanceListItem" 
     android:textColor="@android:color/white" 
     android:textSize="40sp" /> 
</RelativeLayout> 
+0

谢谢你,我会用match_parent修改我所有的fill_parent – Weizen

+0

scaleType是否解决了你的问题? –

0

试试这个代码

<?xml version="1.0" encoding="utf-8"?><?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/your_image" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@mipmap/ic_launcher" 
     android:scaleType="fitEnd" 
     android:layout_alignParentStart="true" 
     android:background="@drawable/green_gradiant" 
     android:padding="10dp" /> 

    <TextView 
     android:id="@+id/content" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:fontFamily="casual" 
     android:paddingBottom="10dp" 
     android:paddingStart="5dp" 
     android:paddingTop="10dp" 
     android:text="Hello Three" 
     android:textAppearance="?attr/textAppearanceListItem" 
     android:textColor="@android:color/white" 
     android:textSize="40sp" /> 
</FrameLayout> 

创建此文件绘制

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item> 
    <shape android:shape="rectangle"> 
     <gradient android:angle="0" 
      android:startColor="#64FFDA" 
      android:centerColor="#4464FFDA" 
      android:endColor="#0064FFDA"/> 
    </shape> 
</item> 
</selector>