我有一个如下的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/logo_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/logos_background">
</ImageView>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_alignBottom="@+id/logo_background"
>
<TextView
android:id="@+id/logoDetails"
android:text="Test Logo details"
android:textSize="15sp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/stockQuantity"
android:layout_centerHorizontal="true"
android:textSize="20sp"
android:layout_below="@+id/logoDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x10"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
我需要在另一个布局中多次包含此布局,我已按以下方式完成:
<HorizontalScrollView
android:layout_below = "@+id/selectLayout"
android:id="@+id/pager"
android:scrollbars="none"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<include layout="@layout/viewpager_item_layout"/>
<include layout="@layout/viewpager_item_layout"/>
<include layout="@layout/viewpager_item_layout"/>
<include layout="@layout/viewpager_item_layout"/>
<include layout="@layout/viewpager_item_layout"/>
<include layout="@layout/viewpager_item_layout"/>
<include layout="@layout/viewpager_item_layout"/>
</LinearLayout>
</HorizontalScrollView>
这将产生以下结果:
![enter image description here](https://istack.dev59.com/zKbwh.webp)
我原本打算使用view pager来实现这一点,但是它会占据整个屏幕的宽度和高度,所以行不通。