Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

android: two pane layout isn't loading scaled layout version of fragmnet

I have a fragment with following layout versions:

layout (default)
    /w320dp
    /w360dp
    /w450dp
    /w700dp

I would like to implement a two pane layout but there is a strange behavior that I was not expected. Let’s say I have a layout sw450land dp that consists of 2 FragmentContainerViews. So screen width in landscape is 700dp. Since the width is 700dp, I thought that each Container would load a layout version of w320dp. But instead, each Container loads a layout version w700dp.

So I was wondering if this is a normal behavior? If so, why is the layout size of the fragment not adjusted to the size of the container?

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DualModeActivity">

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragment_container_01"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:background="@color/yellow_light"
        android:name="com.example.mytestapplicationnew.DualModeFragment"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@id/fragment_container_02"
        />

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/fragment_container_02"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:background="@color/blue_light"
        android:name="com.example.mytestapplicationnew.DualModeFragment"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toEndOf="@id/fragment_container_01"
        app:layout_constraintEnd_toEndOf="parent"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="sw 450 land"
        android:textSize="30sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        />
</androidx.constraintlayout.widget.ConstraintLayout>

Image layout sw450dp-land

question from:https://stackoverflow.com/questions/65922071/android-two-pane-layout-isnt-loading-scaled-layout-version-of-fragmnet

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...