[英]how to set padding or margin to linear layout?
我有一個線性布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_menu"
android:layout_width="fill_parent"
android:layout_height="70px"
android:layout_alignParentBottom="true"
android:background="@drawable/footer_bar"
android:gravity="center" >
</LinearLayout>
當我設定條件
if (constant.getscreenresolution() >= 800) {
//i want to make it height * 2
}
那么如何設置layout params
?
用於填充:
LinearLayout mLayout = (LinearLayout)findViewById(R.id.layout_menu);
mLayout.setPadding(left, top, right, bottom);
LinearLayout mLayout = (LinearLayout)v.findViewById(R.id.ll_winfowindo);
int left= (int) activity.getResources().getDimension(R.dimen._18sdp);
int top=(int) activity.getResources().getDimension(R.dimen._22sdp);
int right=(int) activity.getResources().getDimension(R.dimen._18sdp);
int bottom=(int) activity.getResources().getDimension(R.dimen._34sdp);
mLayout.setPadding(left, top, right, bottom);
希望這能幫助你
LinearLayout.LayoutParams layout_param= new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.fill_parent,
height * 2);
mLayout = (LinearLayout) findViewById(R.id.layout_menu);
mLayout.setLayoutParams(layout_param);
你不應該這樣做。 首先,您使用像素(px)而不是設備無關像素(dp)這樣的事情會創建僅適用於特定設備屏幕配置的UI。 您需要了解Android如何解決屏幕密度的變化,以便您的應用與屏幕密度無關。 從這里開始:
http://developer.android.com/guide/practices/screens_support.html
將邊距添加到線性布局: -
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30, 20, 30, 0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.