如何居中按鈕,使故10px的過每一面。在左側和右側基本上100%寬減10px。Android的中心按鈕
3
A
回答
12
嘗試:
layout_width="fill_parent"
layout_marginLeft="10dip"
layout_marginRight="10dip"
8
可以設置maragin左,mariagn權,如果你曾經使用相對佈局,那麼你可以使用下面的參數 layout_centerInParent,機器人的:layout_centerVertical,機器人:layout_centerHorizontal
如果要將按鈕置於垂直居中,則使用居中垂直真,或者如果要將居中按鈕置於水平居中,則使用居中水平真 ,如下圖所示
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SignUp Here"
android:id="@+id/mysignup"
android:layout_alignBottom="@+id/mylogin"
android:layout_weight="1"
android:layout_centerInParent="true" <!-- use depending upon your need -->
android:layout_centerVertical="true" <!-- use depending upon your need -->
android:layout_centerHorizontal="true" <!-- use depending upon your need -->
/>
傾角是指密度Indepent像素,這意味着,如果您設置的值10,這是相同的所有設備,其中爲PX(像素)取絕對值,所以你的定位可能出錯的一些設備,這就是爲什麼,也使的不是,你可以用蘸作爲DP太多,編譯器轉換DP沾
3
第一:忘掉像素,總是使用DP爲單位。 你想添加它programaticaly或通過佈局的xml文件?
如果您需要添加它programaticaly使用:
LinearLayout layout = new LinearLayout(context);
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
Button button = new Button(context);
button.setText("Some label");
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT,
1);
params.setMargins(10, 0, 10, 0);
button.setLayoutParams(params);
layout.addView(button);
如果你想從佈局文件中添加不喜歡以下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:paddingTop="3dp"
android:paddingRight="10dp" android:paddingLeft="10dp"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<Button android:layout_height="fill_parent" android:id="@+id/scroll_story_title"
android:ellipsize="end" android:layout_gravity="center"
android:maxLines="2" android:gravity="center"
android:text="Something to show to the user and that's pretty cool"
android:layout_marginTop="3dp" android:textSize="11sp"
android:layout_width="fill_parent"></Button>
相關問題
- 1. 在android中的心形按鈕
- 2. 中心按鈕
- 3. Android中心佈局隱藏按鈕
- 4. 按鈕中心CSS
- 5. 按鈕位於按鈕中心的對齊按鈕iOS
- 6. 中心導航按鈕
- 7. 中心登錄按鈕
- 8. 中心對齊表+按鈕
- 9. Swift CGRect使中心按鈕
- 10. 中心三個按鈕
- 11. 對齊按鈕到中心
- 12. 按鈕應在中心和桌面旁邊的按鈕,在中心
- 13. 容器中的中心按鈕
- 14. 流體div中的中心按鈕
- 15. 按鈕中的中心圖像
- 16. 中心對齊按鈕中的圖形
- 17. 輸入按鈕中的中心文本
- 18. 鏈接按鈕中的文本中心?
- 19. LinearLayout中的中心圖像按鈕
- 20. Android用戶界面 - 對齊中心的按鈕,垂直排列
- 21. 如何設置底部和中心的按鈕? - android
- 22. Android:中心按鈕水平。和vert。在ViewGroup中
- 23. 提交按鈕上的中心文本
- 24. 中心按鈕的可能模式
- 25. 按鈕下方的中心文字
- 26. AutoLayout中心兩側的兩個按鈕
- 27. 以我的導航按鈕爲中心
- 28. 與HTML/CSS的中心按鈕
- 29. 按鈕內的中心路徑內容
- 30. 把按鈕放在div的中心
感謝那些工作。爲什麼使用dip而不是px? – Somk 2011-02-17 12:41:07