2016-10-09 17 views
0

私は以下のようなコードを持つlistactivity.javaを持っています。それは activity_main_listapps1.xmlとlistview_layoutファイルを使用することに注意してください。CoordinatorLayoutのAndroidリストビューでスクロール可能にする方法は?

<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は:activity_main_listapps1.xmlは

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); 

<?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> 

このコードはできスクロールしません。私はandroid:layout_heightをmatch_parentに追加しようとしました。まだ見当たりません。

+1

アプリケーションバーレイアウトからURリストビューを削除し、そしてappbarlayout外に書き込み、また座標レイアウト内のネストされたスクロールビュー内に書き込みます。 – HAXM

+1

その後appview:layout_behavior = "@文字列/ appbar_scrolling_view_behavior"をリストビュー – HAXM

+0

に追加しました。ありがとうございました。私はappbarlayoutの外でリストビューを削除&配置しました。 scrollableとlayout_behaviorに関する他の2つの提案を試してみましょう –

答えて

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さえ)は良い考えではありません。 (別のスクロール可能なビューの中に1つのスクロール可能なビュー)。また、私はこの事件をテストし、私のListViewはただ一つの要素を示しました。 – Yar

+0

@ Yar、ご了承いただき、ありがとうございます。 – HAXM

関連する問題