我試圖將影像以這種線性布局居中,但它只是向左對齊,我可以做些什么來解決這個問題。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/ic_menu_edit" />
</LinearLayout>
uj5u.com熱心網友回復:
嘗試設定layout_gravity="center"為 ImageView 和orientation="vertical"LinearLayout。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/ic_menu_edit" />
</LinearLayout>

LinearLayout 旨在將多個子視圖垂直或水平地放置在一行中。當您放置單個子 View 時,您不必使用 LinearLayout,但您可以只使用 FrameLayout。
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/ic_menu_edit" />
</FrameLayout>
uj5u.com熱心網友回復:
添加android:gravity="center"到線性布局
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/ic_menu_edit" />
</LinearLayout>
或者添加android:layout_gravity="center"到 ImageView
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@android:drawable/ic_menu_edit"
/>
它應該以任何一種方式作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/326264.html
