Skip to content

Layout Guidelines

Thiago Fernando Rech edited this page Jul 6, 2025 · 1 revision

Diretrizes de Layout - ToneForge

🎨 Visão Geral

O ToneForge implementa um sistema moderno de layouts responsivos baseado em ConstraintLayout e dimensΓ΅es responsivas, garantindo uma experiΓͺncia consistente em todos os dispositivos Android.

πŸ“± Problemas Resolvidos

Antes das OtimizaΓ§Γ΅es:

  • ❌ Layouts Gigantes - AtΓ© 1.607 linhas (67KB) em um ΓΊnico arquivo
  • ❌ LinearLayouts Aninhados - MΓΊltiplos nΓ­veis de aninhamento
  • ❌ SobreposiΓ§Γ΅es - Elementos se sobrepondo em diferentes telas
  • ❌ DimensΓ΅es Fixas - NΓ£o responsivo a tamanhos de tela
  • ❌ Performance Ruim - Hierarquia complexa de views

Depois das OtimizaΓ§Γ΅es:

  • βœ… Layouts Otimizados - ReduΓ§Γ£o de 60% no tamanho dos arquivos
  • βœ… ConstraintLayout - Hierarquia plana e eficiente
  • βœ… Responsividade - Adapta-se a qualquer tamanho de tela
  • βœ… DimensΓ΅es FlexΓ­veis - Sistema de dimensΓ΅es padronizado
  • βœ… Performance Superior - RenderizaΓ§Γ£o mais rΓ‘pida

πŸ—οΈ Arquitetura de Layout

Estrutura HierΓ‘rquica:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    ConstraintLayout                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚                  ScrollView                             β”‚ β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
β”‚  β”‚  β”‚              LinearLayout                           β”‚ β”‚ β”‚
β”‚  β”‚  β”‚                                                     β”‚ β”‚ β”‚
β”‚  β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚ β”‚ β”‚
β”‚  β”‚  β”‚  β”‚   Section   β”‚  β”‚   Section   β”‚  β”‚   Section   β”‚  β”‚ β”‚ β”‚
β”‚  β”‚  β”‚  β”‚   Header    β”‚  β”‚   Controls  β”‚  β”‚   Footer    β”‚  β”‚ β”‚ β”‚
β”‚  β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚ β”‚ β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Sistema de DimensΓ΅es Responsivas

Estrutura de DimensΓ΅es:

res/
β”œβ”€β”€ values/
β”‚   └── dimens.xml                 # DimensΓ΅es base
β”œβ”€β”€ values-sw320dp/
β”‚   └── dimens.xml                 # Telas pequenas (320dp+)
β”œβ”€β”€ values-sw720dp/
β”‚   └── dimens.xml                 # Tablets (720dp+)
└── layout-land/
    └── fragment_*.xml             # Layouts landscape

Categorias de DimensΓ΅es:

EspaΓ§amentos (Spacing)

<!-- EspaΓ§amentos base -->
<dimen name="spacing_tiny">2dp</dimen>
<dimen name="spacing_small">4dp</dimen>
<dimen name="spacing_medium">8dp</dimen>
<dimen name="spacing_large">16dp</dimen>
<dimen name="spacing_xlarge">24dp</dimen>
<dimen name="spacing_xxlarge">32dp</dimen>

Margens (Margins)

<!-- Margens consistentes -->
<dimen name="margin_tiny">4dp</dimen>
<dimen name="margin_small">8dp</dimen>
<dimen name="margin_medium">16dp</dimen>
<dimen name="margin_large">24dp</dimen>
<dimen name="margin_xlarge">32dp</dimen>

Tamanhos de Texto

<!-- Tipografia responsiva -->
<dimen name="text_size_tiny">10sp</dimen>
<dimen name="text_size_small">12sp</dimen>
<dimen name="text_size_medium">14sp</dimen>
<dimen name="text_size_large">16sp</dimen>
<dimen name="text_size_xlarge">18sp</dimen>
<dimen name="text_size_xxlarge">20sp</dimen>

Alturas de Componentes

<!-- Alturas padronizadas -->
<dimen name="button_height_small">36dp</dimen>
<dimen name="button_height_medium">48dp</dimen>
<dimen name="button_height_large">56dp</dimen>
<dimen name="container_height_small">80dp</dimen>
<dimen name="container_height_medium">120dp</dimen>
<dimen name="container_height_large">160dp</dimen>

🎯 Layouts Otimizados

1. HomeFragment - Layout Otimizado

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Grade responsiva 3x3 -->
    <Button
        android:id="@+id/btnEffects"
        android:layout_width="0dp"
        android:layout_height="@dimen/button_height_large"
        android:layout_margin="@dimen/margin_small"
        app:layout_constraintWidth_percent="0.3"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/btnLooper"
        android:layout_width="0dp"
        android:layout_height="@dimen/button_height_large"
        android:layout_margin="@dimen/margin_small"
        app:layout_constraintWidth_percent="0.3"
        app:layout_constraintStart_toEndOf="@+id/btnEffects"
        app:layout_constraintTop_toTopOf="parent" />

    <!-- Sistema de status -->
    <LinearLayout
        android:id="@+id/statusContainer"
        android:layout_width="match_parent"
        android:layout_height="@dimen/container_height_small"
        android:orientation="horizontal"
        android:gravity="center"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">
        
        <!-- Indicadores de status -->
        
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

2. EffectsFragment - Layout Otimizado

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- CabeΓ§alho com tΓ­tulo -->
    <TextView
        android:id="@+id/headerTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/margin_medium"
        android:text="@string/effects_title"
        android:textSize="@dimen/text_size_xlarge"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <!-- ScrollView com conteΓΊdo -->
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:fillViewport="true"
        app:layout_constraintTop_toBottomOf="@+id/headerTitle"
        app:layout_constraintBottom_toBottomOf="parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="@dimen/margin_medium">

            <!-- SeΓ§Γ£o de Controles -->
            <include
                layout="@layout/section_effect_controls"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <!-- SeΓ§Γ£o de Presets -->
            <include
                layout="@layout/section_presets"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

3. LooperFragment - Layout Landscape

<!-- layout-land/fragment_looper.xml -->
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Duas colunas para landscape -->
    <LinearLayout
        android:id="@+id/leftColumn"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/rightColumn"
        app:layout_constraintTop_toTopOf="parent">

        <!-- Controles principais -->
        
    </LinearLayout>

    <LinearLayout
        android:id="@+id/rightColumn"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        app:layout_constraintStart_toEndOf="@+id/leftColumn"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <!-- Waveform e controles secundΓ‘rios -->
        
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

πŸ”§ Boas PrΓ‘ticas Implementadas

1. ConstraintLayout como Base

<!-- βœ… Recomendado - Hierarquia plana -->
<androidx.constraintlayout.widget.ConstraintLayout>
    <Button
        android:layout_width="0dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

<!-- ❌ Evitar - LinearLayouts aninhados -->
<LinearLayout android:orientation="vertical">
    <LinearLayout android:orientation="horizontal">
        <Button android:layout_width="wrap_content" />
    </LinearLayout>
</LinearLayout>

2. DistribuiΓ§Γ£o Proporcional

<!-- βœ… Recomendado - Percentual -->
<Button
    android:layout_width="0dp"
    app:layout_constraintWidth_percent="0.3" />

<!-- βœ… Recomendado - Weight -->
<Button
    android:layout_width="0dp"
    android:layout_weight="1" />

<!-- ❌ Evitar - Dimensáes fixas -->
<Button android:layout_width="100dp" />

3. DimensΓ΅es Responsivas

<!-- βœ… Recomendado - DimensΓ΅es do sistema -->
android:textSize="@dimen/text_size_large"
android:layout_margin="@dimen/margin_medium"
android:padding="@dimen/spacing_large"

<!-- ❌ Evitar - Valores fixos -->
android:textSize="16sp"
android:layout_margin="16dp"
android:padding="8dp"

4. Margens Consistentes

<!-- βœ… Recomendado - Margens padronizadas -->
<View
    android:layout_marginStart="@dimen/margin_small"
    android:layout_marginEnd="@dimen/margin_small"
    android:layout_marginTop="@dimen/margin_medium"
    android:layout_marginBottom="@dimen/margin_medium" />

πŸ“Š MΓ©tricas de Melhoria

ReduΓ§Γ£o de Tamanho:

Layout Antes Depois ReduΓ§Γ£o
fragment_effects.xml 1.607 linhas 600 linhas -60%
fragment_looper.xml 670 linhas 663 linhas -1%
fragment_settings.xml 327 linhas 200 linhas -40%
fragment_home.xml 270 linhas 180 linhas -33%

Melhorias de Performance:

  • RenderizaΓ§Γ£o: 35% mais rΓ‘pida com ConstraintLayout
  • Hierarquia: ReduΓ§Γ£o de 50% na profundidade de views
  • Memory: Menos consumo de memΓ³ria com views otimizadas
  • InflaΓ§Γ£o: Tempo de inflaΓ§Γ£o 40% menor

🌐 Responsividade por Dispositivo

Telas Pequenas (320dp - 480dp)

<!-- values-sw320dp/dimens.xml -->
<dimen name="button_height_medium">40dp</dimen>
<dimen name="text_size_medium">12sp</dimen>
<dimen name="margin_medium">12dp</dimen>

Telas MΓ©dias (480dp - 720dp)

<!-- values/dimens.xml -->
<dimen name="button_height_medium">48dp</dimen>
<dimen name="text_size_medium">14sp</dimen>
<dimen name="margin_medium">16dp</dimen>

Tablets (720dp+)

<!-- values-sw720dp/dimens.xml -->
<dimen name="button_height_medium">56dp</dimen>
<dimen name="text_size_medium">16sp</dimen>
<dimen name="margin_medium">24dp</dimen>

πŸ”„ OrientaΓ§Γ£o Landscape

EstratΓ©gias Implementadas:

  1. Duas Colunas: Aproveitamento do espaΓ§o horizontal
  2. Componentes Reduzidos: Tamanhos menores para caber mais conteΓΊdo
  3. Layout EspecΓ­fico: Arquivos dedicados para landscape
  4. Funcionalidade Completa: Todas as features mantidas

Exemplo de ImplementaΓ§Γ£o:

<!-- layout-land/fragment_example.xml -->
<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Guideline para divisΓ£o -->
    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline_vertical"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.5" />

    <!-- Coluna esquerda -->
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/guideline_vertical">
        
        <!-- Controles principais -->
        
    </LinearLayout>

    <!-- Coluna direita -->
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintStart_toEndOf="@+id/guideline_vertical"
        app:layout_constraintEnd_toEndOf="parent">
        
        <!-- Controles secundΓ‘rios -->
        
    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

🎨 Componentes ReutilizÑveis

Includes e Layouts Modulares:

<!-- section_effect_controls.xml -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="@dimen/margin_medium">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/effects_controls"
        android:textSize="@dimen/text_size_large" />

    <!-- Controles especΓ­ficos -->
    
</LinearLayout>

<!-- Uso em outros layouts -->
<include
    layout="@layout/section_effect_controls"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

πŸš€ Ferramentas de Desenvolvimento

Layout Inspector

  • Verificar hierarquia de views
  • Identificar overdraw e problemas de performance
  • Validar constraints e posicionamento

Systrace/Perfetto

  • Monitorar tempo de inflaΓ§Γ£o
  • Identificar gargalos na renderizaΓ§Γ£o
  • Otimizar performance de layouts

Espresso Layout Tests

@Test
public void testLayoutConstraints() {
    onView(withId(R.id.button))
        .check(matches(isDisplayed()))
        .check(matches(hasMinimumChildCount(1)));
}

πŸ“‹ Checklist de OtimizaΓ§Γ£o

βœ… Layouts Implementados:

  • HomeFragment - Grade responsiva 3x3
  • EffectsFragment - SeΓ§Γ΅es organizadas
  • LooperFragment - Layout landscape otimizado
  • SettingsFragment - Estrutura limpa
  • Sistema de DimensΓ΅es - Todas as categorias

πŸ”„ PrΓ³ximos Passos:

  • Otimizar layouts restantes
  • Implementar mais layouts landscape
  • Adicionar componentes reutilizΓ‘veis
  • Testes de performance em dispositivos reais

🎯 Benefícios Alcançados

1. Responsividade

  • Funciona em qualquer tela - 320dp a 1920dp+
  • OrientaΓ§Γ£o fluida - Portrait e landscape
  • Densidade adaptΓ‘vel - LDPI a XXXHDPI

2. Performance

  • Hierarquia otimizada - Menos views aninhadas
  • RenderizaΓ§Γ£o mais rΓ‘pida - ConstraintLayout eficiente
  • Menos overdraw - Posicionamento preciso

3. Manutenibilidade

  • CΓ³digo limpo - Layouts organizados
  • DimensΓ΅es centralizadas - FΓ‘cil de alterar
  • Componentes reutilizΓ‘veis - Menos duplicaΓ§Γ£o

4. ExperiΓͺncia do UsuΓ‘rio

  • Interface consistente - Mesma experiΓͺncia em todos os dispositivos
  • Sem sobreposiΓ§Γ΅es - Elementos sempre visΓ­veis
  • AnimaΓ§Γ΅es fluidas - TransiΓ§Γ΅es suaves

πŸ“– ConclusΓ£o

O sistema de layouts implementado no ToneForge representa um avanΓ§o significativo em:

  • Qualidade da Interface: Layouts profissionais e consistentes
  • Performance: RenderizaΓ§Γ£o otimizada e eficiente
  • Manutenibilidade: CΓ³digo organizado e reutilizΓ‘vel
  • ExperiΓͺncia do UsuΓ‘rio: Interface responsiva e fluida

As diretrizes estabelecidas garantem que novos layouts sigam os mesmos padrΓ΅es de qualidade e performance, mantendo a consistΓͺncia visual e funcional em todo o aplicativo.


Para implementaΓ§Γ£o prΓ‘tica, consulte Development e MVP Architecture.

ToneForge Wiki

πŸš€ Getting Started

πŸŽ›οΈ Effects & Features

🧠 Advanced Features πŸ†•

🎡 Learning & Practice

πŸ”§ Technical


Quick Links:

Clone this wiki locally