gpt4 book ai didi

android - LinearLayout 使用 drawableLeft 将文本对齐到中心 View

转载 作者:行者123 更新时间:2023-11-30 02:03:28 24 4
gpt4 key购买 nike

我无法将图像与 TextView 对齐。

我希望它看起来像什么: expected result

实际情况:

Actual Result

请忽略背景色、图片大小。该问题与将图像与 TextView 对齐有关。

我试过下面的代码:

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableStart="@drawable/icon_checkin"
android:gravity="center"
android:text="@string/check_in"
android:drawablePadding="-20sp"
style="@style/roboto4F4F4Flight21"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/icon_checkout"
android:text="@string/check_out"
style="@style/roboto4F4F4Flight21"
android:gravity="center"
/>
</LinearLayout>

注意:我使用了 android:drawablePadding="-20sp" 但没有成功。

还试过:

       <TableLayout 
android:id="@+id/linear_today_attendance"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns = "*"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/icon_checkin"
android:gravity="center"
android:text="@string/check_in"
android:drawablePadding="-20sp"
style="@style/roboto4F4F4Flight21"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/icon_checkout"
android:text="@string/check_out"
style="@style/roboto4F4F4Flight21"
android:gravity="center"
/>
</TableRow>
</TableLayout>

最佳答案

不是最干净的选项,但它应该可以工作:

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/icon_checkin"
android:text="@string/check_in"
style="@style/roboto4F4F4Flight21" />
</LinearLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/icon_checkout"
android:text="@string/check_out"
style="@style/roboto4F4F4Flight21" />
</LinearLayout>
</LinearLayout>

关于android - LinearLayout 使用 drawableLeft 将文本对齐到中心 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31140783/

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