在相对布局中显示不同位置和大小的图像

问题描述 投票:0回答:1

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

<?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个回答
0
投票

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

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

我希望这可以帮到你!

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.