gpt4 book ai didi

android - 如何对齐表格行中的项目(左 - 中 - 右)

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:54:00 24 4
gpt4 key购买 nike

我正在尝试对齐表格行中的项目(左/中/右位置),但我可以让它工作有人可以帮我看看下面的代码 fragment ,,,

表格行

应该对齐textview1 = 左textview2 = 居中imgview1 = 右

表格行的xml

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">


<TextView
android:id="@+id/focast_day"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="left"
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="false"
android:singleLine="true"
android:text="@string/na_msg"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />


<TextView
android:id="@+id/focast_day_temp"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="false"
android:singleLine="true"
android:text="@string/na_msg"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />

<ImageView
android:id="@+id/focast_day_skyIcon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="right"
android:scrollHorizontally="false" />

</TableRow>

我的表格布局

        <TableLayout
android:id="@+id/weatherforcastTable"
android:layout_width="fill_parent"
android:stretchColumns="2"
android:layout_height="wrap_content"
android:layout_below="@+id/today_temp"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp" >
</TableLayout>

向表格行填充数据的代码

 for (Forecastday forecastday : forcastDayList) {


View view = inflater.inflate(R.layout.weather_forcast_day_view, null);
TextView focast_day = (TextView) view.findViewById(R.id.focast_day);
TextView focast_day_temp = (TextView) view.findViewById(R.id.focast_day_temp);
ImageView focast_day_skyIcon = (ImageView) view.findViewById(R.id.focast_day_skyIcon);

TableRow row = new TableRow(_appContext);
focast_day.setText(fmtDate);


focast_day_temp.setText(forecastday.getHigh().getCelsius() +ApplicationConstants.STRING_SPACE +ApplicationConstants.CELSIUS_DEGREES);
focast_day_temp.setId(count);


focast_day_skyIcon.setImageBitmap(forecastday.getSkyiconBitMap());


row.addView(view);
weatherforcastTable.addView(row, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
}

最佳答案

你能试试这个吗:在 TableLayout 上 stretchColumns="0,1,2"

<TableLayout
android:id="@+id/weatherforcastTable"
android:layout_width="fill_parent"
android:stretchColumns="0,1,2"
android:layout_height="wrap_content"
android:layout_below="@+id/today_temp"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp" >
</TableLayout>

关于android - 如何对齐表格行中的项目(左 - 中 - 右),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14940526/

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