原佈局嘗試在垂直 LinearLayout 中放置 RelativeLayout(含 Button)與 FrameLayout,期望 Button 左側、FrameLayout 內容右側。但 FrameLayout 默認子視圖靠左,且 RelativeLayout 寬度 wrap_content 導致佈局擠壓。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="16dp">
<!-- 左側按鈕 -->
<Button
android:id="@+id/buybtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buy_button" />
<!-- 右側視頻縮略圖區域,佔據剩餘空間 -->
<FrameLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="16dp">
<ImageView
android:id="@+id/videothumbimage"
android:layout_width="match_parent"
android:layout_height="170dp"
android:scaleType="centerCrop"
android:src="@drawable/demo_thumb_home" />
<ImageButton
android:id="@+id/videothumb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/button_play_on" />
</FrameLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<Button
android:id="@+id/buybtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="@string/buy_button" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/buybtn"
android:layout_marginStart="16dp">
<!-- 內容同前 -->
</FrameLayout>
</RelativeLayout>
FrameLayout 本身不具備「靠右」佈局能力,需在**父容器**層面通過水平 LinearLayout(權重)或 RelativeLayout(相對定位)實現左右分佈。外層包裹一層水平佈局是最直觀穩健的方案。