Tot*_*tus 6 android margin centering android-layout android-percentrelativelayout
编辑:我已收到两个关于固定保证金的综合答案.虽然我已经决定使用固定边距而不是重量边距,但最初的问题仍未解决.
我想在Android中获得以下设计:
一个居中的垂直列表(TextViews,EditViews等),它留下大约10%的水平空间作为左/右边距,带有背景.
我尝试过但没有工作/部分工作的内容:
(在最后两种情况下,我的Eclipse也抱怨其中一个布局是多余的.)
我没有发布代码,认为这更像是一个与原则相关的问题.实现这一目标的最佳方法是什么?
谢谢.
对应于最后一个测试用例的XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:weightSum="1.0"
android:background="#013c57" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:layout_gravity="center"
android:orientation="vertical" >
<!-- Stuff -->
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是创建此类布局的最简单的 xml 代码,检查一下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000"
android:gravity="center">
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9617 次 |
| 最近记录: |