Android TableLayout does not beat

0

This is the layout I currently have:

Andhere'sthecode:

<?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 want is this:

WhatamImissing?WherecanIgetsomethingthatwillgivemea"north" to solve this?

    
asked by anonymous 22.07.2016 / 01:24

2 answers

0

Well, Table layout is a little boring to organize right-handed images because of the 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:

    
22.07.2016 / 22:18
0

I think it would be nice to use LinearLayout and change its height

<?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>
    
22.07.2016 / 20:00