我正在开始使用Android。我无法进行简单的布局。
我想用一个LinearLayout
到位置二TextViews
在单行中。一TextView
一个在左侧,另一个在右侧(类似于 CSS 中的 float:left、float:right)。
这可能吗,还是我需要使用不同的ViewGroup
或者进一步布局嵌套来完成它?
这是我到目前为止所拥有的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="horizontal" android:padding="10sp">
<TextView android:id="@+id/mytextview1" android:layout_height="wrap_content" android:text="somestringontheleftSomestring" android:layout_width="wrap_content"/>
<TextView android:id="@+id/mytextview2" android:layout_height="wrap_content" android:ellipsize="end"
android:text="somestringontheright" android:layout_width="wrap_content"/>
</LinearLayout>
Use a RelativeLayout http://developer.android.com/intl/fr/reference/android/widget/RelativeLayout.html with layout_alignParentLeft http://developer.android.com/intl/fr/reference/android/widget/RelativeLayout.LayoutParams.html#attr_android:layout_alignParentLeft and layout_alignParentRight http://developer.android.com/intl/fr/reference/android/widget/RelativeLayout.LayoutParams.html#attr_android:layout_alignParentRight:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:id="@+id/mytextview1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:id="@+id/mytextview2"/>
</RelativeLayout>
Also, 你可能应该使用dip (or dp) 而不是sp在你的布局中 http://developer.android.com/intl/fr/guide/practices/screens_support.html#density-independence. sp
反映文本设置以及屏幕密度,因此它们通常仅用于调整文本项目的大小。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)