【问题标题】:Fill the width in landscape mode with two imageviews用两个图像视图填充横向模式的宽度
【发布时间】:2017-07-31 10:48:06
【问题描述】:

我有这个rec​​yclerview,背景是用imageviews制作的。我在纵向和横向中有这两种情况。如何用新的图像视图或相同颜色的东西填充那里的空白?

这是我的 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 这是我想放在每个背景图像视图左侧的图像视图,以填充景观中的空间。谢谢你的帮助。

【问题讨论】:

    标签: java android imageview landscape


    【解决方案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"。

    希望这对您有所帮助..如果您仍然遇到问题,请告诉我...

    【讨论】:

      【解决方案2】:
      <ImageView
       android:layout_width="match_parent"
       .... />
      

      你也可以使用scaleTypeattribute

      【讨论】:

      • 对不起,伙计,但你甚至没有试图帮助我:)
      • 对不起。创建景观变化布局。
      【解决方案3】:

      首先,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>
      

      【讨论】:

      • 谢谢,我会用match_parent修改我所有的fill_parent
      【解决方案4】:

      试试这个代码

      <?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>
      

      【讨论】:

        猜你喜欢
        • 2023-03-05
        • 1970-01-01
        • 1970-01-01
        • 2011-07-01
        • 1970-01-01
        • 2013-08-07
        • 1970-01-01
        • 1970-01-01
        • 2016-04-14
        相关资源
        最近更新 更多