我需要知道如何修改我的列表項目佈局,以便它們不填滿屏幕寬度,並且活動背景在側面可見。Listview項目小於屏幕寬度,因此活動背景在側面可見
我試過各種layout_width,但沒有成功。
我只是想知道如何做到這一點時,我將應用該規則在我的情況
編輯:列表項的 XML代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:layout_marginLeft="20dp"
android:clipToPadding="true"
android:background="#FFFFFF"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/post_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_post" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/post_nick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/post_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/post_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
仍然相同,我用xml代碼更新問題 – codareee
您的XML不包含ListView - 我想它是列表行。您需要在ListView本身上設置邊距屬性,而不是在行佈局中。 – SirKnigget
完全沒有影響,我沒有使用xml的listview中使用自定義佈局,但我從createView()中的代碼修改它() – codareee