我正在使用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()是填充我的列表功能。
用一些虛擬數據填充我的數組後,我使用適配器添加到我的列表視圖。但是,我能看到的只是一次一行的數據。我可以在一行數據之間滾動。
謝謝。
無需要滾動視圖列表視圖。刪除它 – Dhina
不需要在'ScrollView'裏面放置'ListView'。 'ListView'是可滾動的內容本身 – Wizard