gpt4 book ai didi

android - 线性布局中心

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:33:30 32 4
gpt4 key购买 nike

我在 LinearLayout 中的对齐有一点问题。

我试图让前两个元素左对齐,第三个元素在屏幕中央。

这是我的代码(从 id、text、src 中清除):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/color_background"
>

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
</TextView>
</LinearLayout>
</LinearLayout>

alt text http://img807.imageshack.us/img807/5953/imageg.png

这是我想要做的,左边是粉色和黄色,中间是红色

pink = imageview
yellow = 1st texview
red = 2nd textview

有什么想法吗?

最佳答案

所以你需要使用的代码如下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:id="@+id/image"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/image"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
</RelativeLayout>

关于android - 线性布局中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3330352/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com