2017-02-09 5 views
-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> 

Теперь я установил макет для заголовка сверху. Затем под этим макетом следует Imageview, текстовое представление и список, и только 1 textview находится внутри listview. listview может отличаться по размеру.Я хочу, чтобы текущий макет был изменен, чтобы я мог прокручивать весь макет.

Проблема в том, что размер списка очень большой, я могу прокручивать экран, назначенный listview. Но, я хочу прокрутить весь экран.

Чтобы решить эту проблему, я добавил scrollview вне первого линейного выхода. Однако, это не сработало. (Изображение исчезло)

Что мне делать?

ответ

0

вы можете сделать свой ListView addheaderview, и поставить ImageView и TextView в 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; 
    } 
} 

}

Смежные вопросы