我在一個幀佈局中有兩個線性佈局。以編程方式更改線性佈局頂部邊距android
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"
android:orientation="vertical">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/image12">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/layoutbtnlinear_aboutme"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:gravity="bottom"
android:layout_marginTop="10dp"
android:background="#b2b2b2"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imgShare_layout_aboutme"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_gravity="right|center|end"
android:layout_weight="1.63"
android:src="@drawable/ic_share" />
<TextView
android:id="@+id/txtTitle_layout_aboutme"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_gravity="left"
android:layout_weight="0.3"
android:fontFamily="Times New Roman"
android:text="About Me"
android:textColor="@android:color/black"
android:textSize="35sp"
android:textStyle="italic" />
</LinearLayout>
<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageButton
android:id="@+id/btnSlidingDrawerHandler_layout_aboutme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ic_1_navigation_collapse" />
<ListView
android:id="@+id/listView_layout_aboutme"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:footerDividersEnabled="true"
android:dividerHeight="4px"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideInset"
android:scrollbars="vertical">
</ListView>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
在這裏,我與ID layoutbtnlinear_aboutme
塞汀線性佈局top margin
到10dp,但在代碼中,我想改變這個10dp到50dp一些條件我如何編程改變這種頂邊距?
採取對谷歌一看,還有很多其他的問題,與此類似,像http://stackoverflow.com/questions/9678785/android-setting-layoutparams-programmatically – bogdan