마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

[java] 한화면에 Fragment 레이아웃 똑같은거 4개로 나누는법

0 추천

ㅇ

대형 태블릿 디스플레이에서 사람4명이 화면영역을 나눠서 1인 태블릿을 쓰는거처럼 구현할려고 합니다. fragment를 쓰면된다는데 그림처럼 딱 4개로 나눠지지도 않고 2개까지만 소환되고 비율도 짤려서 나오더군요.. 사진처럼 똑같은 레이아웃을 한화면에 4개로 나눌려면 어떻게 해야하나요? 

페피 (220 포인트) 님이 2022년 12월 7일 질문

1개의 답변

0 추천

LinearLayout, ConstraintLayout, GridLayout, TableLayout 등을 사용하실 수 있을 것 같구요. (아마 RelativeLayout도 가능할 듯)

ConstraintLayout을 사용할 경우, 아래처럼 하실 수 있습니다.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frame1"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#FFFFFF"
        app:layout_constraintEnd_toStartOf="@id/frame2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toTopOf="@id/frame3"
        />

    <FrameLayout
        android:id="@+id/frame2"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#FF0000"
        app:layout_constraintBottom_toBottomOf="@id/frame1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/frame1"
        app:layout_constraintTop_toTopOf="@id/frame1" />

    <FrameLayout
        android:id="@+id/frame3"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#00FF00"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@id/frame4"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/frame1" />

    <FrameLayout
        android:id="@+id/frame4"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#0000FF"
        app:layout_constraintBottom_toBottomOf="@id/frame3"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/frame3"
        app:layout_constraintTop_toTopOf="@id/frame3" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

spark (227,530 포인트) 님이 2022년 12월 7일 답변
...