0

I have a FrameLayout and a Listview inside the FrameLayout. I populate the Listview with another Layout. The problem is if I set the layout_height to wrap_content my getview is getting called multiple time for a single record and if I set the layout_height to fill_parent or wrap_content my getview is being called 3 times for a single record. If I set the layout_height to some dp value it is working fine. I mean I dont have any issues with performance and my getview is getting called only once for a record. So I get the screen height and width programmatically using

Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth(); 
int height = display.getHeight();

But if I set the width and height of my Listview with the value measured using the above code the last record of my Listview is partially not visible. I guess this should be because the obtained screen height includes the title bar height, status bar height and notification bar height.

So if that is the prob can someone help me with calculating the available screen height? That is screen height-titlebar height-statusbar height-notification bar height? else What is the problem? why my last record in my ListView is not fully visible?

XML File

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ListView android:id="@+id/android:list"
android:background="#ffffff"    
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:clickable="true"
android:fastScrollEnabled="true"   
android:smoothScrollbar="true"    
/>
</FrameLayout>

Then I set the layout_height and layout_width of the list view in my java code as

Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth(); 
int height = display.getHeight();
FrameLayout.LayoutParams parameters = new FrameLayout.LayoutParams((int)(width),(int)(height));
ListView listview=(ListView) getListView();
listview.setLayoutParams(parameters );
user001
  • 11
  • 6

2 Answers2

0

Hi all thanks for your help I changed my code as below and now its working :)

Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int height=0;
int width = display.getWidth(); 
switch (metrics.densityDpi) 
{ 
case DisplayMetrics.DENSITY_HIGH:
height = display.getHeight() - (48*2);
break;
case DisplayMetrics.DENSITY_MEDIUM:
height = display.getHeight() - (32*2);                              
break;
case DisplayMetrics.DENSITY_LOW:
height = display.getHeight() - (24*2);
break;
default:
height = display.getHeight() - (48*2);
}
FrameLayout.LayoutParams parameters = new FrameLayout.LayoutParams((int)(width),(int)(height));
ListView listview=(ListView) getListView();
listview.setLayoutParams(parameters );
user001
  • 11
  • 6
0

in java:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int s_width,s_height;
s_width = metrics.widthPixels;
s_height = metrics.heightPixels/3;
TableRow.LayoutParams parameters = new TableRow.LayoutParams(s_width,s_height);
LinearLayout b_list_table=(LinearLayout) findViewById(R.id.b_list_table);
b_list_table.setLayoutParams(parameters);

in xml:

<?xml version="1.0" encoding="utf-8"?>
   <RelativeLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >

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






       <TableRow
           android:layout_width="match_parent"
           android:layout_height="180dip"
           android:id="@+id/b_list_table"
           >
           <ListView android:id="@+id/list"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:layout_weight="1"
               android:drawSelectorOnTop="false"/>
       </TableRow>






       <TableRow
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           >
           <ListView android:id="@+id/listf"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"

               android:layout_weight="1"
               android:drawSelectorOnTop="false"/>
       </TableRow>

   </LinearLayout>