【问题标题】:Showing Image in Different Position and Size in Relative Layout在相对布局中显示不同位置和大小的图像
【发布时间】:2019-03-14 06:32:53
【问题描述】:

我可以在相对布局中查看回收视图图像,但它显示的图像如固定表格行。布局在设计中没有外观和感觉。我正在寻找不同大小和不同位置的每个图像。任何建议表示赞赏。 我在下面添加了布局和适配器类。

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

    <android.support.v7.widget.CardView
        android:layout_width="372dp"
        android:layout_height="161dp"
        android:layout_marginStart="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        app:cardBackgroundColor="@color/light_gray"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="301dp"
            android:background="@color/white">

            <ImageView
                android:id="@+id/Image"
                android:layout_width="349dp"
                android:layout_height="109dp"
                android:layout_below="@+id/Name"
                android:layout_alignEnd="@+id/Name"
                android:layout_alignParentBottom="true"
                android:layout_marginTop="10dp"
                android:layout_marginEnd="-185dp"
                android:layout_marginBottom="153dp"
                android:scaleType="center"
                app:srcCompat="@drawable/ic_launcher_background"
                android:layout_marginRight="-185dp"
                android:layout_alignRight="@+id/Name" />
        </RelativeLayout>
    </android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>

适配器

{
      override fun getItemCount(): Int
    {
        return list.size
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder
    {
        val view= LayoutInflater.from(parent.context).inflate(R.layout.list_row_food_one,parent,false)
        return ViewHolder(view)
    }
    override fun onBindViewHolder(holder: ViewHolder, position: Int)
    {
        holder.bindItem(list[position],fragment)
    }
    class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView)
    {
        fun bindItem(test:TestDetail?,fragment: FragmentOne)=with(itemView)
        {
            var testImage: ImageView =itemView.findViewById(R.id.testImage)
            Picasso.get().load(test!!.itemImage).into(testImage)
        }
    }
}

【问题讨论】:

  • 您遇到的主要问题是什么?每张图片的尺寸是否不同?
  • 我发布我的答案看看它。
  • 所有图片大小相同,但我正在寻找不同位置的图片。
  • 你可以使用约束布局来实现这个

标签: android android-relativelayout android-design-library androiddesignsupport


【解决方案1】:

使用线性布局,它会根据您在设计中的外观和感觉给出,因为它在屏幕中具有固定位置,但在相对布局中它可以相对于其他组件,因此它的位置不是固定的。

所以,我更喜欢使用线性布局而不是相对布局。

希望对你有帮助!

谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    • 1970-01-01
    • 2011-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多