Android 构建布局的最有效方法
我会有数百个这样的布局,请看下图,所以我需要以最有效的方式构建它。共有三个区域,第一个区域由底线对齐,左侧区域包含ImageView,第二个区域包含两个TextView,一个位于另一个下方。在第二个视图下有另一个具有TextView的视图。我是否应该使用TableLayout作为容器,使用LinearLayout作为第二个容器?这样会有效率吗?多谢各位Android 构建布局的最有效方法,android,android-layout,Android,Android Layout,我会有数百个这样的布局,请看下图,所以我需要以最有效的方式构建它。共有三个区域,第一个区域由底线对齐,左侧区域包含ImageView,第二个区域包含两个TextView,一个位于另一个下方。在第二个视图下有另一个具有TextView的视图。我是否应该使用TableLayout作为容器,使用LinearLayout作为第二个容器?这样会有效率吗?多谢各位 第一个建议是使ImageView更高,以便在高度上覆盖两个文本视图,或者使底部文本视图更宽,以覆盖ImageView和上部文本视图 在我看来,这
第一个建议是使ImageView更高,以便在高度上覆盖两个文本视图,或者使底部文本视图更宽,以覆盖ImageView和上部文本视图 在我看来,这样看起来会更好,这个空旷的地方让我感到刺痛 然后我会推荐TableLayout,当然这个布局在单独的文件中,这样你就可以用include.重用它 干杯,希望它能在RelativeLayout中有所帮助。您应该添加AlignParentLeft=true和alignParenttop=true的图像视图,然后将第一个文本视图添加为imageView的右侧,将第二个文本视图添加到第一个文本视图的LayoutBottom 使用相对布局,它们被认为比线性布局更轻。试试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="41dp"
android:layout_marginTop="39dp"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/imageView1"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/imageView1"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 1" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 2" />
</LinearLayout>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/linearLayout1"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/imageView1"
android:text="TextView" />
试试这个,它将为您提供您在问题中描述的布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/img" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="@+id/txt1"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textView1" />
<TextView
android:id="@+id/txt2"
android:layout_below="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="textView1" />
</RelativeLayout>
</LinearLayout>
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bg_l_l"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bg_l_l"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="chintan"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="khetiya"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bg_l_l"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is extra text and this will not spred under the imageview as you can see."
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
是否要将文本分散在图像视图下方?不,底部的文本视图不应分散在图像视图下方。@siik:请参见下面的回答,我不需要将底部的文本视图分散在图像视图下方