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


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="55dp"
        >
        <Button
            android:id="@+id/btn_question_backButton"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/backicon_round"/>

        <TextView
            android:id="@+id/text_question_detail_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:textColor="@color/color_green"
            android:text="Error"
            android:textSize="19dp"

            />
    </RelativeLayout>

    <ImageView
        android:id="@+id/image_question_detail_image"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:scaleType="centerCrop"/>

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

        <TextView
            android:id="@+id/text_question_detail_userComments"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:layout_marginTop="10dp"
            android:layout_weight="1"
            android:layout_marginBottom="25dp"
            />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3">

            <ListView
                android:id="@+id/list_question_detail_expComments"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:divider="@android:color/transparent"
                android:dividerHeight="10dp"></ListView>

        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

Now, I set layout for title on the top. Then, a Imageview, a textview and a listview follow below this layout, and only 1 textview is inside listview. listview can vary in size.

The problem is, if the size of the listview is very big, I can only scroll the screen assigned to listview. But, I want scroll the entire screen.

To solve this problem, I added scrollview outside of the first linearlayout. However, It didn't work.(the imageview disappeared)

What can I do?

심희수
  • 123
  • 1
  • 2
  • 5

1 Answers1

0

you can make your listview addheaderview,and put your imageview and textview into headerview

yourlayout.xml

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


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="55dp">

    <Button
        android:id="@+id/btn_question_backButton"
        android:layout_width="50dp"
        android:layout_height="50dp" />

    <TextView
        android:id="@+id/text_question_detail_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Error"
        android:textColor="#000000"
        android:textSize="19dp"

        />
</RelativeLayout>


<ListView
    android:id="@+id/list_question_detail_expComments"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@android:color/transparent"
    android:dividerHeight="10dp"></ListView>

lv_header.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="wrap_content"
android:orientation="vertical"
>


<ImageView
    android:id="@+id/image_question_detail_image"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="3"
    android:scaleType="centerCrop" />


<TextView
    android:id="@+id/text_question_detail_userComments"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="25dp"
    android:layout_marginTop="10dp"
    android:layout_weight="1"
    android:textSize="20dp" />

Activity.class

public class MainActivity extends AppCompatActivity {

private ListView list_question_detail_expComments;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    list_question_detail_expComments = (ListView) findViewById(R.id.list_question_detail_expComments);
    View lvHeaderView = View.inflate(this,R.layout.lv_header,null);
    list_question_detail_expComments.addHeaderView(lvHeaderView);
    list_question_detail_expComments.setAdapter(new LvAdapter());

}

private class LvAdapter extends BaseAdapter{

    @Override
    public int getCount() {
        return 20;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

            TextView tv = new TextView(MainActivity.this);

             tv.setText("test"+i);

        return tv;
    }
}

}

dalei
  • 1