RAMAZAN
@RAMAZAN
Java-developer

Помощь в верстки дизайна в Android

Как можно сделать, что бы кнопка всегда была ровно на пол экрана, т.е. их там 4 как в передаче «Кто хочет стать миллионером». Нужно что бы в зависимости от содержимого, они не меняли свой размер, у меня вышло сделать только, если мало текста, они расположены норм, если текст в одной больше в другой меньше, одна кнопка как бы забирает немного места другой.


<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    android:background="@color/background"
    android:orientation="horizontal"
    >  
    
    
    <TableRow android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="1dp" android:layout_weight="0.45">  
        <TextView android:paddingTop="30dp" android:layout_height="wrap_content" android:id="@+id/question" style="@style/EffectTextViewQuestion" android:text="TextViewsdf" android:layout_width="wrap_content"></TextView>
    </TableRow>    

    <TableRow android:layout_width="fill_parent" android:layout_height="1dp" android:layout_weight="0.55" android:background="@color/background">
            <TableLayout android:id="@+id/tableLayout2" android:layout_height="match_parent" android:layout_width="wrap_content" android:layout_weight="1">
                <TableRow android:id="@+id/tableRow3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.5">
                    <Button android:textColor="@color/text" android:layout_margin="10dp" android:text="Button" android:id="@+id/answer1" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="0.1"></Button>
                    <Button android:textColor="@color/text" android:layout_margin="10dp" android:text="Button" android:id="@+id/answer2" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="0.1"></Button>
                </TableRow>
                <TableRow android:id="@+id/tableRow4" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="0.5">
                    <Button android:textColor="@color/text" android:layout_margin="10dp" android:text="Button" android:id="@+id/answer3" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="0.1"></Button>
                    <Button android:textColor="@color/text" android:layout_margin="10dp" android:text="Button" android:id="@+id/answer4" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_weight="0.1"></Button>
                </TableRow>
            </TableLayout>
    </TableRow>  
 
</TableLayout>
  • Вопрос задан
  • 5657 просмотров
Пригласить эксперта
Ответы на вопрос 3
Когда указываете layout_weight, попробуйте поиграться с соответствующими параметрами layout_width и layout_height. Я не помню подробностей, но либо wrap_content, либо 0dp должен подойти, если я правильно понял задачу.

Ну и заодно, некрасиво использовать рядом match_parent и fill_parent.
Ответ написан
@GSysoev

Для таких целей RelativeLayout - самое то. TableLayout - не очень удобная вещь Вот 4 кнопки:


<?xml version="1.0" encoding="utf-8"?>
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"><view android:id="@+id/emptyview" android:layout_width="0dp" android:layout_height="0dp" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" /><button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_toleftof="@+id/emptyview" android:text="Button1" />

    

    <button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_alignparenttop="true" android:layout_torightof="@+id/button1" android:text="Button2" />

    <button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignright="@+id/button1" android:layout_below="@+id/button1" android:text="Button3" />

    <button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/button2" android:layout_alignparentright="true" android:layout_below="@+id/button2" android:text="Button4" />

</relativelayout>

Ответ написан
Вы делаете HTML вёрстку?
Почему вы используете TableLayout?
<LinearLayout
	orientation="vertical"
	weighSum="1">
	<View
		layout_width="wrap_content"
		layout_height="0dp"
		layout_weight=".5" />
	<TextView
		layout_gravity="center" />
	<View
		layout_width="wrap_content"
		layout_height="0dp"
		layout_weight=".5" />
</LinearLayout>
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы