2017-07-31 74 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>