我遇到了以下問題:我實現了一個HorizontalScrollView
,其中包含一個LinearLayout
和一個ImageView
。在這種情況下,圖像大約是屏幕寬度的50%。所以我想集中它。不幸的是,我發現它的中心唯一的方法是在LinearLayout
上使用layout_gravity="center"
。Android - 爲LinearLayout編程設置Layout_Gravity
這裏是我的xml:
<HorizontalScrollView
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/myImg"
android:layout_width="wrap_content"
android:adjustViewBounds="true"
android:layout_height="150dp"/>
</LinearLayout>
</HorizontalScrollView>
但我需要設置layout_gravity
編程。有沒有人有一個想法,我可以如何實現這一目標,或知道一種不同的方式?我通過Google找到的所有東西都不適合我,比如this post。
謝謝!
你試過encapsultaing的ImageView的一個LinearLayout中,如圖所示在您訪問的崗位設置該佈局的參數? – ClaireG
是的,我試過了......不工作 – Ron