Подтвердить что ты не робот

Как выравнивать элемент в строке таблицы (влево - вправо-вправо)

Я пытаюсь выровнять элементы в строке таблицы (позиции слева/в центре/вправо), но я мог бы определить, как это работает, кто-то может помочь мне взглянуть ниже фрагмента,,

Таблица строк

должен совпадать с textview1 = слева textview2 = центр 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

        <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));
                    }
4b9b3361

Ответ 1

Не могли бы вы попробовать: stretchColumns = "0,1,2" в 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>

Ответ 2

Вы пытались использовать "layout_gravity" вместо "gravity" в первом и последнем столбцах в макете xml для строки? Это может устранить вашу проблему, выровняв прогноз_прогноз слева от родительской таблицы, а прогноз__дай_II вправо.

Здесь хорошая визуализация гравитации против layout_gravity

http://sandipchitale.blogspot.com/2010/05/linearlayout-gravity-and-layoutgravity.html

Ответ 3

Это работало для меня.

<TableRow 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center">

Надеюсь, что это поможет.