ฉันหันหน้าไปทางปัญหาที่พบบ่อยมาก: ScrollViewฉันวางออกกิจกรรมและตอนนี้ก็จะเปิดออกก็ควรแสดงไม่กี่รายการที่อยู่ในนี้ วิธีปกติในการทำเช่นนั้นคือใช้สิ่งที่มีอยู่ListAdapterเชื่อมต่อกับListViewและบูมฉันจะมีรายการของฉัน
แต่คุณไม่ควรวางสิ่งที่ซ้อนกันListViewไว้ในScrollViewขณะที่มันเลื่อนขึ้น - แม้แต่ Android Lint ก็บ่นเกี่ยวกับเรื่องนี้
นี่คือคำถามของฉัน:
ฉันจะเชื่อมต่อListAdapterกับ a LinearLayoutหรือสิ่งที่คล้ายกันได้อย่างไร
ฉันรู้ว่าโซลูชันนี้จะไม่ปรับขนาดสำหรับรายการจำนวนมาก แต่รายการของฉันสั้นมาก (<10 รายการ) ดังนั้นจึงไม่จำเป็นต้องใช้มุมมองซ้ำ ประสิทธิภาพที่ชาญฉลาดฉันสามารถใช้ชีวิตได้ด้วยการวางมุมมองทั้งหมดลงในไฟล์LinearLayout.
วิธีแก้ปัญหาหนึ่งที่ฉันคิดขึ้นมาคือการวางเค้าโครงกิจกรรมที่มีอยู่ในส่วน headerView ของไฟล์ListView. แต่รู้สึกเหมือนกำลังใช้กลไกนี้ในทางที่ผิดดังนั้นฉันจึงมองหาวิธีที่สะอาดกว่านี้
ไอเดีย?
อัปเดต:เพื่อสร้างแรงบันดาลใจไปในทิศทางที่ถูกต้องฉันเพิ่มเค้าโครงตัวอย่างเพื่อแสดงปัญหาของฉัน:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/news_detail_layout"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical"
              android:visibility="visible">
    <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="#FFF"
            >
        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:paddingLeft="@dimen/news_detail_layout_side_padding"
                android:paddingRight="@dimen/news_detail_layout_side_padding"
                android:paddingTop="@dimen/news_detail_layout_vertical_padding"
                android:paddingBottom="@dimen/news_detail_layout_vertical_padding"
                >
            <TextView
                    android:id="@+id/news_detail_date"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:gravity="center_horizontal"
                    android:text="LALALA"
                    android:textSize="@dimen/news_detail_date_height"
                    android:textColor="@color/font_black"
                    />
            <Gallery
                    android:id="@+id/news_detail_image"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:paddingTop="5dip"
                    android:paddingBottom="5dip"
                    />
            <TextView
                    android:id="@+id/news_detail_headline"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:gravity="center_horizontal"
                    android:text="Some awesome headline"
                    android:textSize="@dimen/news_detail_headline_height"
                    android:textColor="@color/font_black"
                    android:paddingTop="@dimen/news_detail_headline_paddingTop"
                    android:paddingBottom="@dimen/news_detail_headline_paddingBottom"
                    />
            <TextView
                    android:id="@+id/news_detail_content"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"
                    android:text="Here comes a lot of text so the scrollview is really needed."
                    android:textSize="@dimen/news_detail_content_height"
                    android:textColor="@color/font_black"
                    />
            <!---
                HERE I NEED THE LIST OF ITEMS PROVIDED BY THE EXISTING ADAPTER. 
                They should be positioned at the end of the content, so making the scrollview smaller is not an option.
            ---->                        
        </LinearLayout>
    </ScrollView>
</LinearLayout>
อัปเดต 2ฉันเปลี่ยนหัวข้อข่าวเพื่อให้เข้าใจง่ายขึ้น (ได้รับการโหวตลดลง!)