Tablelayout Android does not beat

Asked

Viewed 72 times

0

This is the layout I currently have:

Resultado atual

And this is the code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="br.com.teste.MainActivity"
    android:background="#d6d7d7">

    <android.support.v7.widget.Toolbar
        android:id="@+id/menu_principal"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

    </android.support.v7.widget.Toolbar>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/menu_principal">

        <TableLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/menu_principal"
            android:layout_centerHorizontal="true"
            android:layout_margin="0dp"
            android:stretchColumns="2">

            <TableRow
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="0dp"
                android:layout_weight="1"
                android:layout_margin="0dp">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/btnDescontos"
                    android:src="@drawable/descontos"
                    android:layout_weight="1"
                    android:layout_span="1"/>

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/btnEventos"
                    android:src="@drawable/eventos"
                    android:layout_weight="1"
                    android:layout_span="1"/>

            </TableRow>

            <TableRow
                android:orientation="horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="0dp"
                android:layout_weight="1"
                android:layout_margin="0dp">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/btnGastronomia"
                    android:src="@drawable/gastronomia"
                    android:layout_weight="1" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/btnEsportes"
                    android:src="@drawable/esportes"
                    android:layout_weight="1" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/btnEmpregos"
                    android:src="@drawable/empregos"
                    android:layout_weight="1" />

            </TableRow>

            <TableRow
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="0dp"
                android:layout_weight="1"
                android:layout_margin="0dp">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/btnServicos"
                    android:src="@drawable/servicos"
                    android:layout_weight="1" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/btnBemestar"
                    android:src="@drawable/bemestar"
                    android:layout_weight="1" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/btnCultura"
                    android:src="@drawable/cutura"
                    android:layout_weight="1" />
            </TableRow>

        </TableLayout>
    </LinearLayout>


</RelativeLayout>

And what I wish for is this:

inserir a descrição da imagem aqui

What am I missing? Where can I get something that gives me a "north" to solve this?

  • I think Gridview would be better to arrive at your result.

2 answers

0

I think it would be good to use Linearlayout and change the height of it

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#d6d7d7"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="br.com.teste.MainActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/menu_principal"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

</android.support.v7.widget.Toolbar>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/menu_principal"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="140dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/btnDescontos"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:src="@drawable/icon" />

        <ImageView
            android:id="@+id/btnEventos"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="139dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/btnGastronomia"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon" />

        <ImageView
            android:id="@+id/btnEsportes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon" />

        <ImageView
            android:id="@+id/btnEmpregos"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="128dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/btnServicos"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon" />

        <ImageView
            android:id="@+id/btnBemestar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon" />

        <ImageView
            android:id="@+id/btnCultura"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/icon" />
    </LinearLayout>
</LinearLayout>
</RelativeLayout>

0


Well, Table layout is a bit boring to organize right pictures on account of column divisions.

Follow an example with Linearlayouts

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:orientation="horizontal"
    >
    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/place1"
        android:scaleType="centerCrop" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/place2"
        android:scaleType="centerCrop" />


</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:orientation="horizontal"
    >
    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/place2"
        android:scaleType="centerCrop" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/place1"
        android:scaleType="centerCrop" />
    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/place2"
        android:scaleType="centerCrop" />


</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:orientation="horizontal"
    >
    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/place1"
        android:scaleType="centerCrop" />

    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/place2"
        android:scaleType="centerCrop" />
    <ImageView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:src="@drawable/place1"
        android:scaleType="centerCrop" />


</LinearLayout>

What would generate the following layout:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.