对齐ImageView& LinearLayout中的TextView [英] Align ImageView & TextView inside LinearLayout
问题描述
我有一个LinearLayout,里面有一个ImageView和TextView。我想将LinearLayout的中心与ImageView下方的ImageView和TextView对齐。
I have a LinearLayout and inside, a ImageView and TextView. I want to align the center of the LinearLayout the ImageView and the TextView below the ImageView.
我只在LinearLayout中获得顶部对齐ImageView。我该怎么做?
I only get the top align ImageView in LinearLayout. How I can do?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:layout_margin="8dp"
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="@+id/boton"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center"
android:background="@drawable/plano"
android:gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Plano"
android:textSize="23sp"
android:textStyle="bold"
/>
</LinearLayout>
推荐答案
我会告诉你如何做同样的服用RelativeLayout和TextView的复合可绘制的优点:
I'll show you how to do the same taking advantage of a RelativeLayout and a TextView's compoundDrawable:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_margin="8dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:drawableTop="@drawable/plano"
android:drawablePadding="8dp"
android:text="Plano"
android:textSize="23sp"
android:textStyle="bold"
/>
</RelativeLayout>
复合绘图有助于保持视图计数,因此本质上加快了布局
Compound drawables help keeping down the View count, and therefore intrinsically speed up the layout
关键是 android:drawableTop =@ drawable / plano
这取代了顶部的图像。
你也可以设置右侧,左侧,下侧图像。
甚至全部一起。
The key is android:drawableTop="@drawable/plano"
This replaces the top image.
You can also set a Right, Left, Bottom side image.
Even all together.
这篇关于对齐ImageView& LinearLayout中的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!