这是我想要实现的目标,但我没有做到。
This is a long lable: {image1}{image1}
Short label: {image1}{image1}
Other label length: {image1}{image1}
请注意,标签两端的冒号已对齐,并且相同尺寸的图像也将对齐。不同长度的标签将不会对齐。现实中的标签都只是一个单词,因此空间应该是一个问题,但是单词的宽度并不相同。
下面的布局将所有内容居中,但它们以这种方式出现。
This is a long lable: {image1}{image1}
Short label: {image1}{image1}
Other label length: {image1}{image1}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:id="@+id/layout_one">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="@string/image_one"
android:id="@+id/one"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/digit_border"
android:padding="2dp"
android:adjustViewBounds="true"
android:id="@+id/one1"
android:src="@drawable/five"
android:scaleType="centerCrop"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/digit_border"
android:padding="2dp"
android:adjustViewBounds="true"
android:id="@+id/one2"
android:src="@drawable/five"
android:scaleType="centerCrop"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/layout_days"
android:layout_below="@+id/layout_two"
android:gravity="center"
android:paddingTop="2dp"
android:paddingBottom="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="@string/image_two"
android:id="@+id/two"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/digit_border"
android:padding="2dp"
android:adjustViewBounds="true"
android:id="@+id/two1"
android:src="@drawable/five"
android:scaleType="centerCrop"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/digit_border"
android:padding="2dp"
android:adjustViewBounds="true"
android:id="@+id/two2"
android:src="@drawable/five"
android:scaleType="centerCrop"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/layout_three"
android:layout_below="@+id/layout_days"
android:gravity="center"
android:paddingTop="2dp"
android:paddingBottom="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp"
android:text="@string/image_three"
android:id="@+id/three"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/digit_border"
android:padding="2dp"
android:adjustViewBounds="true"
android:id="@+id/three1"
android:src="@drawable/five"
android:scaleType="centerCrop"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/digit_border"
android:padding="2dp"
android:adjustViewBounds="true"
android:id="@+id/hour2"
android:src="@drawable/three2"
android:scaleType="centerCrop"/>
</LinearLayout>
您可以将权重分配给textView并将权重设置为正确,这样它们将为所有三行占据相同的空间,而向右的重力将确保文本正确对齐。以下是布局文件,您可以根据自己的情况设置权重。
第一个具有基本布局的XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="2dp"
android:paddingTop="2dp" >
<TextView
android:id="@+id/one"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:gravity="right|center_vertical"
android:text="text1 : "
android:textSize="22sp" />
<ImageView
android:id="@+id/one1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:adjustViewBounds="true"
android:padding="2dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/one2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:adjustViewBounds="true"
android:padding="2dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher" />
</LinearLayout>
创建完整视图的第二个XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="2dp"
android:paddingTop="2dp" >
<include
android:id="@+id/layout_one"
layout="@layout/test_item" />
<include
android:id="@+id/layout_two"
layout="@layout/test_item" />
<include
android:id="@+id/layout_three"
layout="@layout/test_item" />
</LinearLayout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句