1

関連する activity.xml コードを持つアクティビティがあります。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/pattern_background"
android:orientation="vertical" >

<ScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginBottom="5dp"
    android:layout_weight="1"
    android:clickable="false" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        ...

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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />
    </LinearLayout>
</ScrollView>

<include
    android:id="@+id/layoutComments"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"        
    layout="@layout/widget_comentarios_fragment" >
</include>

id llComments の LinearLayout では、次のコードを使用して、CommentsFragment というフラグメントをアクティビティから動的に導入します。

private Fragment commentsFragment;
private FragmentTransaction ft;
...
llComentarios = (LinearLayout) findViewById(R.id.llComments);
...
Bundle args  = new Bundle();
args.putString(Constants.IDMODEL, getId());
commentsFragment = CommentsFragment.newInstance(args);
ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.llComments, commentsFragment).commit();

フラグメントに関連付けられた xml ファイルは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"   
android:orientation="vertical">

<ListView
    android:id="@+id/comments"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:divider="@color/transparent"
    android:dividerHeight="10dp"
    android:paddingLeft="@dimen/indicator_internal_padding"
    android:paddingRight="@dimen/indicator_internal_padding" />
</LinearLayout>

私が解決できない問題は、リストビューの高さを固定しないと、リスト内の複数のアイテム (実際には 1 つと 3 つ目のアイテムを表示しています) を表示することです。追加するアイテムと同じ数に適応する必要があります。アダプターを介してフラグメント内のリストに。レイアウトとビューでさまざまな高さの組み合わせを試しましたが、まだうまくいきません。多分私は他の人と年をとっています。

どんな助けでも大歓迎です。

前もって感謝します

4

1 に答える 1

1

数日後、私は正確な問題を見つけました。私は ListView を ScrollView に含めていましたが、これは明らかに Android 開発者には推奨されていません。ここで詳細情報を探すことができます:なぜ ListView を ScrollView で使用できないのですか?

とにかく、やりたい場合は、ハックでそれを行うことができます。これらの提案を見てみましょう: ListView を折りたたまずに ScrollView に入れるにはどうすればよいですか?

私にとってはうまくいきました。問題が解決しました。

于 2013-08-04T19:17:22.463 に答える