Layout Problem,Please help

Quickly share your Android Code Snippets here...

Layout Problem,Please help

Postby ramesh_bh » Fri Oct 22, 2010 10:55 am

HI,

my requirement is like i have to display a table with lot of rows, at the bottom i have to display a footer of three buttons, i was done both of them but the problem is, the footer buttons appear on the top of the table list, i want to stop the table rows before footer , and i want to put it in a scroll view, so that i can see all the rows and footer also.
If i put scroll view to the table the table is coming for the entire page.
Please help
ramesh_bh
Junior Developer
Junior Developer
 
Posts: 20
Joined: Thu Oct 07, 2010 4:58 am

Top

Re: Layout Problem,Please help

Postby urbantrad » Sat Oct 23, 2010 4:42 pm

I'm not quite sure how you want the layout to appear; should the footer be always visible, or just appear at the very bottom of the list?
In the first case, you can just put the scrollview in a linearlayout with the footer underneath it.
In the second case of course you can just add the buttons without much trouble to the bottom of the table.
urbantrad
Senior Developer
Senior Developer
 
Posts: 104
Joined: Thu Sep 09, 2010 10:19 pm

Re: Layout Problem,Please help

Postby ramesh_bh » Mon Oct 25, 2010 5:46 am

HI

Thanks for the reply, my layout should look like a table with a scroll view, and a footer of 3 buttons,
i have designed a layout and here i am giving my code below, the table is coming to the entire page, i want to stop the table before footer. Please hlep !!
Code: Select all
Gallery grid_main;
   TableLayout table;
   LinearLayout myLayout[] = new LinearLayout[44];
   TextView myText[] = new TextView[4];
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contacts_table);
       
        table = (TableLayout)findViewById(R.id.ContactsLayout);
        for(int i=0;i<44;i++) {
         myLayout[i] = new LinearLayout(this);
         
         for(int j=0;j<4;j++) {
            myText[j] = new TextView(this);
            myText[j].setText("asdf"+i+j);
            myText[j].setPadding(0, 0, 20, 10);
            myText[j].setClickable(true);
            myText[j].setOnClickListener(this);
            myLayout[i].addView(myText[j]);
            
         }      
         myLayout[i].setClickable(true);
         
         myLayout[i].setOnClickListener(this);
         table.addView(myLayout[i]);
      
      }      
       
        grid_main = (Gallery)findViewById(R.id.widget29);
      grid_main.setAdapter(new ImageAdapter(this));
    }
    public class ImageAdapter extends BaseAdapter {
      Context mContext;
      
      public ImageAdapter(Context c){
         mContext = c;
      }
      @Override
      public int getCount() {
         // TODO Auto-generated method stub
         return 1;
      }

      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
         // TODO Auto-generated method stub
         View v = null;
         if(convertView==null){
            LayoutInflater li = getLayoutInflater();
            v = li.inflate(R.layout.footer, null);
            Button b1 = (Button)v.findViewById(R.id.widget40);
            b1.setOnClickListener(TestActivity.this);
         }else  {
            v = convertView;
         }
         return v;
      }
      
      @Override
      public Object getItem(int position) {
         // TODO Auto-generated method stub
         return null;
      }
      @Override
      public long getItemId(int position) {
         // TODO Auto-generated method stub
         return 0;
      }
      
   }
   @Override
   public void onClick(View v) {
      System.out.println("Button 1 Pressed...");
      
   }


and my layouts are : contacts_table.xml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/widget0"
   android:layout_width="fill_parent" android:layout_height="fill_parent"
   xmlns:android="http://schemas.android.com/apk/res/android">
   <ScrollView android:id="@+id/widget41" android:layout_width="wrap_content"
      android:layout_height="wrap_content">

      <TableLayout android:id="@+id/ContactsLayout"
         android:layout_width="fill_parent" android:layout_height="wrap_content"
         android:orientation="vertical" android:stretchColumns="*"
         android:layout_y="40px">
         <TableRow android:id="@+id/widget106" android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:background="#ff424142"
            android:orientation="horizontal">
            <TextView android:id="@+id/widget107" android:layout_width="wrap_content"
               android:layout_height="wrap_content" android:text="Name">
            </TextView>
            <TextView android:id="@+id/widget108" android:layout_width="wrap_content"
               android:layout_height="wrap_content" android:text="Acc Name">
            </TextView>
            <TextView android:id="@+id/amount" android:layout_width="wrap_content"
               android:layout_height="wrap_content" android:text="Email">
            </TextView>
            <TextView android:id="@+id/amount" android:layout_width="wrap_content"
               android:layout_height="wrap_content" android:text="Phone">
            </TextView>
         </TableRow>
      </TableLayout>
   </ScrollView>
   <LinearLayout android:id="@+id/gallery_layou"
      android:layout_width="wrap_content" android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentLeft="true">
   <Gallery android:id="@+id/widget29" android:layout_width="wrap_content"
      android:layout_height="wrap_content" android:layout_x="3px"
      android:layout_y="363px">
   </Gallery>
   </LinearLayout>
</AbsoluteLayout>


footer.xml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/widget0"
   android:layout_width="fill_parent" android:layout_height="fill_parent"
   xmlns:android="http://schemas.android.com/apk/res/android">
   <LinearLayout android:id="@+id/widget38"
      android:layout_width="wrap_content" android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentLeft="true">
      <Button android:id="@+id/widget40" android:layout_width="wrap_content"
         android:layout_height="wrap_content" android:text="Home">
      </Button>
      <Button android:id="@+id/widget39" android:layout_width="wrap_content"
         android:layout_height="wrap_content" android:text="Test">
      </Button>
   </LinearLayout>
</AbsoluteLayout>
ramesh_bh
Junior Developer
Junior Developer
 
Posts: 20
Joined: Thu Oct 07, 2010 4:58 am

Re: Layout Problem,Please help

Postby urbantrad » Sat Oct 30, 2010 1:54 pm

Code: Select all
<AbsoluteLayout android:id="@+id/widget0"
   android:layout_width="fill_parent" android:layout_height="fill_parent" ...

The problem is that you say the TableLayout should fill the parent, causing anything underneat it to have no space left to be drawn. I'm not entirely sure though what the best way of fixing this is, you might want to play around with it a bit.
urbantrad
Senior Developer
Senior Developer
 
Posts: 104
Joined: Thu Sep 09, 2010 10:19 pm

Re: Layout Problem,Please help

Postby blundell » Sun Oct 31, 2010 6:21 pm

I would recommend changing from AbsoluteLayout.

This class is deprecated.
Use FrameLayout, RelativeLayout or a custom layout instead.
http://developer.android.com/reference/ ... ayout.html
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Layout Problem,Please help

Postby Schermvlieger » Sun Oct 31, 2010 6:30 pm

Hi Ramesh,

You can do it like this:

Code: Select all
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">

   
      
   <ScrollView
      xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_height="fill_parent"
       android:layout_width="fill_parent">
          <LinearLayout
              android:orientation="vertical"
               android:layout_width="fill_parent"
                android:layout_height="wrap_content">
   
              </LinearLayout>
      </ScrollView>   

   <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
         android:layout_width="fill_parent"
       android:layout_height="wrap_content">


      *** insert your items here ***


      </LinearLayout>
      
   </LinearLayout>

Schermvlieger
Senior Developer
Senior Developer
 
Posts: 159
Joined: Fri Feb 26, 2010 1:37 pm

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 4 guests