如何在表格行中对齐项目(左-中-右) [英] how to align item in table row (left - center - right)

查看:96
本文介绍了如何在表格行中对齐项目(左-中-右)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to align items in a table row (left/center/right positions), but i could dot get it work can someone help me looking at below snippet,,,

表格行

应与 textview1 =左 textview2 =中心 imgview1 =正确

should align to textview1 = left textview2 = center imgview1 = right

表格行的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>

myTableLayout

myTableLayout

        <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>

用于将数据填充到表行的代码

code for filling the data to table row

 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"

Could you try this : stretchColumns="0,1,2" on the TableLayout

<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>

这篇关于如何在表格行中对齐项目(左-中-右)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆