2015-12-03 32 views
0

我正在使用listView適配器,但我的適配器沒有得到填充父級高度。ListView沒有得到fill_parent高度

的代碼下面給出 Content_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context=".MainActivity" 
    tools:showIn="@layout/app_bar_main"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:orientation="horizontal"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:gravity="right" 
      android:text=" Date : " /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <TextView 
      android:layout_width="110dp" 
      android:layout_height="wrap_content" 
      android:text=" Client " /> 

     <TextView 
      android:layout_width="70dp" 
      android:layout_height="wrap_content" 
      android:text=" Id " /> 

     <TextView 
      android:layout_width="70dp" 
      android:layout_height="wrap_content" 
      android:text=" Amount " /> 

     <TextView 
      android:layout_width="70dp" 
      android:layout_height="wrap_content" 
      android:text=" Due " /> 
    </LinearLayout> 

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical"> 

      <ListView 
       android:id="@+id/listView" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 

       /> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

和main_activity文件:

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { 

    com.zerothtech.khudrotathyav1.Helper Helper = new com.zerothtech.khudrotathyav1.Helper(); 
    private ArrayList<HashMap> list; 

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


     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 

     DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
     ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
       this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
     drawer.setDrawerListener(toggle); 
     toggle.syncState(); 

     NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
     navigationView.setNavigationItemSelectedListener(this); 

     //---ListView---- 
     ListView lview = (ListView) findViewById(R.id.listView); 
     populateList(); 
     listviewAdapter adapter = new listviewAdapter(this, list); 
     lview.setAdapter(adapter); 
     //---ListView---- 
    } 
} 

populateList()是填充我的列表功能。

用一些虛擬數據填充我的數組後,我使用適配器添加到我的列表視圖。但是,我能看到的只是一次一行的數據。我可以在一行數據之間滾動。

謝謝。

+1

無需要滾動視圖列表視圖。刪除它 – Dhina

+1

不需要在'ScrollView'裏面放置'ListView'。 'ListView'是可滾動的內容本身 – Wizard

回答

1

在列表視圖的父佈局文件中刪除滾動視圖設置列表視圖

注意的全高:切勿將列表視圖內滾動視圖

<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <ListView 
      android:id="@+id/listView" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 

      /> 
    </LinearLayout> 
+0

謝謝。有效。 –

+0

這是我的愉快。 pl接受我的回答,所以這對其他人有幫助 –

0

我檢查你的佈局。如果使用列表視圖,則不能在滾動視圖中使用。 我有正確的佈局。

試試這個..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:showIn="@layout/app_bar_main" 
tools:context=".MainActivity"> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right" 
    android:orientation="horizontal"> 

    <TextView 
     android:text=" Date : " 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:layout_gravity="right" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView 
     android:text=" Client " 
     android:layout_width="110dp" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:text=" Id " 
     android:layout_width="70dp" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:text=" Amount " 
     android:layout_width="70dp" 
     android:layout_height="wrap_content" /> 

    <TextView 
     android:text=" Due " 
     android:layout_width="70dp" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 



    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

     <ListView 
      android:id="@+id/listView" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 

      /> 
    </LinearLayout>  

+0

謝謝Destro,但我已經得到了解決方案。 –