如何居中按钮,使故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