如何居中按鈕,使故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. Android瀏覽器中的中心按鈕
- 3. 在android中的心形按鈕
- 4. 中心按鈕
- 5. 中心按鈕
- 6. 的Android按鈕文本啓動中心按鈕
- 7. Android中心佈局隱藏按鈕
- 8. Android移動按鈕總是到中心
- 9. 中心右對齊按鈕 - Android
- 10. CSS中的中心按鈕
- 11. 按鈕中心CSS
- 12. 中心WordPress的按鈕
- 13. 按鈕位於按鈕中心的對齊按鈕iOS
- 14. 中心登錄按鈕
- 15. 中心按鈕文本
- 16. HTML中心輸入按鈕
- 17. Swift CGRect使中心按鈕
- 18. 中心對齊表+按鈕
- 19. 對齊按鈕到中心
- 20. QTabBar :: setTabButton中心按鈕
- 21. 中心三個按鈕
- 22. 中心導航按鈕
- 23. 中心和調整按鈕
- 24. 按鈕應在中心和桌面旁邊的按鈕,在中心
- 25. 如何攔截中心按鈕按
- 26. Java中的中心菜單按鈕
- 27. 鏈接按鈕中的文本中心?
- 28. 容器中的中心按鈕
- 29. 按鈕中的中心圖像
- 30. 中心對齊按鈕中的圖形
感謝那些工作。爲什麼使用dip而不是px? – Somk 2011-02-17 12:41:07