45

ViewPager とタブ付きの ActionBar があります。これらのタブの 1 つに ListView があり、その ListView のオプションの 1 つをタップすると、その行の詳細ビューである子 Fragment が追加されます。

その詳細ビューは、その中に LinearLayout を持つ ScrollView です。ScrollView はmatch_parent/match_parentであり、その中width=match_parentのLinearLayout はheight=wrap_contentです。電話サイズのエミュレーターでは、詳細ビューは必要に応じて画面を埋めますが、タブレットでは、詳細ビューは画面の幅の一部しかカバーしません... ScrollView の幅と LinearLayout の幅は同じですが、両方とも match_parent です。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rootView" style="@style/RootScrollView">

    <LinearLayout android:id="@+id/scrollContentView" style="@style/ScrollViewContent">
        ...
    </LinearLayout>
</ScrollView>

スクロール ビューのスタイルは次のとおりです。

<style name="RootScrollView">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">match_parent</item>
</style>

コンテンツ LinearLayout のスタイルは次のとおりです。

<style name="ScrollViewContent">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:paddingLeft">15dp</item>
    <item name="android:paddingRight">15dp</item>
    <item name="android:orientation">vertical</item>
    <item name="android:background">@drawable/image_legal_paper_tile</item>
</style>

コンテンツ ビューには、次のような繰り返しの背景image_legal_paper_tileがあります。

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/legal_paper_tile" 
    android:gravity="fill_horizontal"
    android:tileMode="repeat" />

そのため、画像は水平方向に伸びて繰り返し、背景に黄色のリーガル ペーパー パッドが作成されます。

これは、リストと詳細ビューが電話エミュレーターのように見えるものです。

ここに画像の説明を入力

これは、リストと詳細ビューが実際のタブレットでどのように見えるかです。黄色のリーガル パッド フラグメントは、画面の幅全体を埋める必要がありますが、そうではありません。

ここに画像の説明を入力

編集:

背景のリーガルペーパーの画像は次のとおりです。

ここに画像の説明を入力

幅320pxです。電話エミュレーターの幅は 480px で、画像は画面の幅いっぱいに正しく伸びます。その後、意図したとおりに垂直方向に繰り返されます。ただし、タブレットの画面幅いっぱいに伸ばすわけではありません。

タブレットに表示される幅は、コンテンツに基づいてサイズが変わるため、画像の本来のサイズではありません。フラグメントが最初に読み込まれるとき、幅は 1 つです。次に、フィールドに入力して計算を実行し、コンテンツ ビューの下部にテキストを追加します。そのテキストは既存のコンテンツより幅が広いため、テキストが設定されると、幅の広いコンテンツをサポートするためにフラグメントの幅が増加します。

つまり、いいえ、タブレットの幅は画像のネイティブ サイズではありません。画像は伸びていますが、完全には伸びていません。

4

5 に答える 5

186

android:fillViewport="true"ScrollView では、 ScrollViewの子と for を使用しandroid:height="wrap_content"ます。さまざまな属性を持つ多くの子を持ちたい場合は、メインの子をコンテナとして作成します。それを として設定しwrap_content、その子を として設定しmatch_parentます。

例 :

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:fillViewport="true">

    <LinearLayout
        android:id="@+id/dynamic_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/dimrix_sub_child"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:visibility="gone" >
        </LinearLayout>

        <LinearLayout
             android:id="@+id/dimrix_sub_child_21"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:visibility="gone" >
        </LinearLayout>
    </LinearLayout>
</ScrollView>

この例では、各子のコードで可視性を設定でき、必要に応じて親と一致します。

于 2013-10-17T13:54:53.403 に答える
0

次のように、parentView がの parentView にConstraintLayout設定されているだけの場合:android:layout_height="0dp"ScrollView

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout>

  <SomeView/>

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp" 
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <YourItens>

        </LinearLayout>

    </ScrollView>

  </LinearLayout>

  <SomeView .../>

</androidx.constraintlayout.widget.ConstraintLayout>
于 2020-08-14T14:39:36.633 に答える
0

回避策を見つけましたが、この回答は受け入れません。誰かが本当の回答を見つけてくれることを願っています。

リスト ビュー フラグメントである onListItemClick() ハンドラーで、詳細フラグメントにいくつかのプロパティ (minWidth と minHeight) を設定しました。次に、詳細フラグメントの onCreateView() メソッドで、最小の幅と高さをその値に設定します。

詳細フラグメントはスペースを適切に埋め、スクロールなどを可能にします。

于 2013-03-18T05:53:06.877 に答える