2016-10-09 5 views
0

나는 아래와 같은 코드를 가진 listactivity.java를 가지고있다. 여기에는 activity_main_listapps1.xml 및 listview_layout 파일이 사용됩니다. activity_main_listapps1.xml이CoordinatorLayout 안의 안드로이드리스트 뷰를 스크롤 할 수있게 만드는 방법?

setContentView(R.layout.activity_main_listapps1); 

String[] from = { "flag","label","cur" ,"right_flag"}; 

    // Ids of views in listview_layout 
    int[] to = { R.id.flag,R.id.txt,R.id.cur,R.id.right_flag}; 

    // Instantiating an adapter to store each items 
    // R.layout.listview_layout defines the layout of each item 
    SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to); 

    // Getting a reference to listview of layout file 
    ListView listView = (ListView) findViewById(R.id.listview); 

    // Setting the adapter to the listView 
    listView.setAdapter(adapter); 

:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/drawer_design_support_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/rootLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 
      <android.support.design.widget.TabLayout 
       android:id="@+id/tab_layout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> 
      <ListView 
       android:id="@+id/listview" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       /> 
     </android.support.design.widget.AppBarLayout> 
    </android.support.design.widget.CoordinatorLayout> 
</android.support.v4.widget.DrawerLayout> 

및 listview_layout.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="horizontal" 
    > 
    <ImageView 
     android:id="@+id/flag" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="hello" 
     android:paddingTop="10dp" 
     android:paddingRight="10dp" 
     android:paddingBottom="10dp" 
     android:layout_weight="1" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_weight="2"> 
     <TextView 
      android:id="@+id/txt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="15dp" 
      /> 

     <TextView 
      android:id="@+id/cur" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="10dp" 
      /> 
    </LinearLayout> 


    <ImageView 
     android:id="@+id/right_flag" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="hello" 
     android:paddingTop="10dp" 
     android:paddingRight="10dp" 
     android:paddingBottom="10dp" 
     android:visibility="visible" 
     android:layout_weight="1" /> 
</LinearLayout> 

이 코드는 수 스크롤되지 않습니다. match_parent에 layout_height를 추가해 보았습니다. 아직 누락 된 것이 있습니다.

+1

또한 좌표 레이아웃 내측 중첩 스크롤 뷰 내부를 작성 appbar 레이아웃에서 UR리스트 뷰를 제거하고 그것을 외부 appbarlayout 물품. – HAXM

+1

그 후 app : layout_behavior = "@ string/appbar_scrolling_view_behavior"를 목록보기 – HAXM

+0

에 추가해 주셔서 감사합니다. appbarlayout 외부에서 listview를 제거하고 배치했습니다. 이제 스크롤 가능 .. 스크롤보기 및 layout_behavior에 관한 다른 두 가지 제안을 시도합니다 –

답변

2

appbar 레이아웃에서 목록보기를 제거하고 appbarlayout 외부에 작성하고 좌표 레이아웃 내부의 중첩 스크롤보기에 쓸 수도 있습니다.

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/drawer_design_support_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/rootLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
     <android.support.design.widget.TabLayout 
      android:id="@+id/tab_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> 
     <ListView 
      android:id="@+id/listview" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /> 
    </android.support.design.widget.AppBarLayout> 
      <android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:fillViewport="true"> 
      <ListView 
      android:id="@+id/listview" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 
     <android.support.v4.widget.NestedScrollView/> 
</android.support.design.widget.CoordinatorLayout> 

+0

ScrollView (심지어 NestedScrollView) 내부의 ListView는 좋은 생각이 아닙니다. (스크롤 할 수있는 다른보기 안에 한 개의 스크롤 가능한보기). 또한, 나는이 사건을 테스트하고 ListView는 단지 하나의 요소만을 보여 주었다. – Yar

+0

@ Yar, 고맙습니다. 감사드립니다. – HAXM

관련 문제