Ответ 1
Используйте
android:minHeight="60px"
В теге TableRow
<TableRow android:id="@+id/task1" android:layout_width="fill_parent"
android:minHeight="60px" android:layout_height="wrap_content">
Я хотел бы знать, как увеличить высоту строки таблицы, чтобы она выглядела пропорционально при больших размерах экрана. В настоящее время все текстовые изображения и edittexts (помещенные в строки таблицы) появляются в левой части экрана, а не занимают весь экран (только в больших размерах экрана). Вот xml, с которым я работаю:
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<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/black_background">
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<TableRow android:id="@+id/TableRow01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="@color/white"
android:visibility="visible"
android:text="@string/Name"
android:layout_weight="0.2"
android:layout_marginLeft="20dp"
android:layout_marginTop="22dp"/>
<EditText android:id="@+id/myName"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:textSize="20sp"
android:visibility="visible"
android:layout_weight="0.3"
android:inputType="number"
android:textColor="@color/black_background"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"/>
<TextView android:id="@+id/error1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="@color/red"
android:visibility="visible"
android:layout_weight="0.5"/>
</TableRow>
<TableRow android:id="@+id/TableRow02"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:visibility="visible"
android:textColor="@color/white"
android:text="@string/address"
android:layout_weight="0.2"
android:layout_marginLeft="20dp" android:layout_marginTop="22dp"/>
<EditText android:id="@+id/address"
android:layout_width="120dip"
android:layout_height="wrap_content"
android:textSize="20sp"
android:visibility="visible"
android:inputType="number"
android:textColor="@color/black_background"
android:layout_weight="0.8"
android:layout_marginLeft="10dp" android:layout_marginTop="10dp"/>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
Используйте
android:minHeight="60px"
В теге TableRow
<TableRow android:id="@+id/task1" android:layout_width="fill_parent"
android:minHeight="60px" android:layout_height="wrap_content">
Пожалуйста, перейдите по этой ссылке, я думаю, это поможет вам. http://developerlife.com/tutorials/?p=307
Обратите внимание, что дети из TableLayout
не могут указать свою ширину, которая всегда FILL_PARENT
. Однако высота может быть определена дочерним элементом, который по умолчанию равен WRAP_CONTENT
. Если дочерний элемент имеет значение TableRow
, высота всегда WRAP_CONTENT
.
Итак, если вы используете TableLayout
с TableRows
, вы не можете установить ширину/высоту (width=FILL_PARENT
и height=WRAP_CONTENT
).
Кстати, TableRow - это просто подкласс LinearLayout. Что вы можете сделать, это указать поведение столбца для сжатия и/или растяжения или нет. Вы также можете скрыть столбец, вызвав setColumnCollapsed в TableLayout и передав ему индекс столбца. Все индексы столбцов начинаются с 0, и вы можете иметь пустые столбцы.
Вы можете просто использовать android: layout_weight. Например, в приведенном ниже коде левая кнопка в два раза больше, чем правая кнопка:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent">
<Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"
android:text="hai" />
<Button android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="2"
android:text="longer sentence" />
</LinearLayout>
Добавьте следующие свойства ко всем вашим TableRow
s:
android:layout_height = "0dp"
android:layout_weight = "1"
Он растягивает всю вашу TableRow
чтобы занимать всю родительскую высоту.
Вы можете установить android:layout_weight
для каждого TableRow
равным 1. Затем измените высоту TableLayout
по своему усмотрению. Это отлично работает для меня!
android:layout_weight="1"
Вы можете применить android:layout_weight
к TableRow и дать равное значение всем строкам таблицы. Строки таблицы будут распределены в оставшемся пространстве линейного макета.
Убедитесь, что вы указали ниже атрибуты TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"