Simple Layout

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Simple Layout

Postby Bear » Fri Jan 22, 2010 3:54 pm

Hello, all
I use table layout with 2 rows. Last row contains 2 image buttons. How can I move one button to the left and another - to the right of row?
Bear
Junior Developer
Junior Developer
 
Posts: 15
Joined: Fri Jan 22, 2010 3:50 pm

Top

Postby Stam » Fri Jan 22, 2010 5:59 pm

By using a Relative Layout, there is an example :

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <RelativeLayout android:orientation="vertical"
  2.  
  3.                 android:layout_width="fill_parent"
  4.  
  5.                 android:layout_height="fill_parent">
  6.  
  7.                 <TextView android:layout_width="wrap_content"
  8.  
  9.                         android:layout_alignParentLeft="true"
  10.  
  11.                         android:layout_height="wrap_content" android:text="left" />
  12.  
  13.                 <TextView android:layout_width="wrap_content"
  14.  
  15.                         android:layout_alignParentRight="true"
  16.  
  17.                         android:layout_height="wrap_content" android:text="right" />
  18.  
  19.         </RelativeLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
Stam
Junior Developer
Junior Developer
 
Posts: 22
Joined: Wed Nov 25, 2009 1:49 pm
Location: Lille, France

Postby Bear » Mon Jan 25, 2010 2:34 pm

Thx, Stam

I create very simple layout

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:layout_width="fill_parent"
  4.    android:layout_height="fill_parent"
  5.    android:orientation="vertical">
  6.     <ImageView
  7.         android:id="@+id/im1"
  8.         android:layout_width="wrap_content"
  9.         android:layout_height="wrap_content"
  10.         android:adjustViewBounds="true"/>    
  11.     <Button
  12.        android:id="@+id/open"
  13.        android:layout_width="wrap_content"
  14.        android:layout_height="wrap_content"
  15.        android:layout_below="@id/camera"
  16.        android:layout_alignParentLeft="true"
  17.        android:layout_alignParentBottom="true"
  18.        android:background="@drawable/open"              
  19.     />
  20.      <Button
  21.        android:id="@+id/close"
  22.        android:layout_width="wrap_content"
  23.        android:layout_height="wrap_content"
  24.        android:layout_alignParentRight="true"
  25.        android:layout_alignParentBottom="true"        
  26.        android:layout_alignTop="@id/im1"
  27.        android:background="@drawable/quit"                    
  28.     />
  29.     <ImageView
  30.         android:id="@+id/im2"
  31.         android:layout_width="wrap_content"
  32.         android:layout_height="wrap_content"
  33.         android:layout_below="@id/camera"
  34.         android:layout_centerHorizontal = "true"
  35.         android:layout_alignLeft="@id/open"
  36.         android:layout_alignRight="@id/exit"
  37.         android:adjustViewBounds="true"/>    
  38. </RelativeLayout>
Parsed in 0.017 seconds, using GeSHi 1.0.8.4


I want to have one big image and 2 buttons and 1 small image at the bottom of screen. I try to set sizes to buttons and images:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. DisplayMetrics metrics = new DisplayMetrics();
  2.                 getWindowManager().getDefaultDisplay().getMetrics(metrics);
  3.                
  4.                 img1.setMaxWidth(metrics.widthPixels);
  5.                 img1.setMaxHeight(metrics.heightPixels-btnHeight);
  6.                
  7.                 img2.setMaxWidth(metrics.widthPixels);
  8.                 img2.setMaxHeight(btnHeight);
  9.                
  10.                 btnClose.setHeight(btnHeight);
  11.                 btnClose.setWidth(btnWidth);
  12.                
  13.                 btnOpen.setHeight(btnHeight);
  14.                 btnOpen.setWidth(btnWidth);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


But right now I have 2 buttons from top to bottom instead of required layout:



Image
Bear
Junior Developer
Junior Developer
 
Posts: 15
Joined: Fri Jan 22, 2010 3:50 pm

Postby Stam » Tue Jan 26, 2010 8:32 am

Hu, can you draw me what do you really want to do ? 'Cause I don't understand, sry ^^ (I think i'm just a stupid French :p :p)


Edit : I see in your xml, if you want to show the 2 buttons at bottom, there is an error here :
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.    <Button
  3.  
  4.        android:id="@+id/close"
  5.  
  6.        android:layout_width="wrap_content"
  7.  
  8.        android:layout_height="wrap_content"
  9.  
  10.        android:layout_alignParentRight="true"
  11.  
  12.        android:layout_alignParentBottom="true"        
  13.  
  14.        [s]android:layout_alignTop="@id/im1"[/s]
  15.  
  16.        android:background="@drawable/quit"                    
  17.  
  18.     />
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Your have to do a
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <Button
  2.  
  3.        android:layout_below="@id/camera"                  
  4.  
  5.     />
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


To set your button under your big image...
Stam
Junior Developer
Junior Developer
 
Posts: 22
Joined: Wed Nov 25, 2009 1:49 pm
Location: Lille, France

Postby Bear » Tue Jan 26, 2010 10:23 am

Hello, Stam!
What I want is shown on picture in my previous post:
1)At the top I want to have Image View.
2)At the bottom: on the left - one button, on the right - another button, between them - image view.
3)I want to set sizes of this controls in my activity, because they'll be different for different resolutions.
4)I want to set image for imageviews also in activity.
My current layout:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.    android:layout_width="fill_parent"
  7.  
  8.    android:layout_height="fill_parent"
  9.  
  10.    android:orientation="vertical"
  11.  
  12.    >
  13.  
  14.     <ImageView
  15.  
  16.         android:id="@+id/im1"
  17.  
  18.         android:layout_width="wrap_content"
  19.  
  20.         android:layout_height="wrap_content"
  21.  
  22.         android:adjustViewBounds="true"/>    
  23.  
  24.     <Button
  25.  
  26.        android:id="@+id/open"
  27.  
  28.        android:layout_width="wrap_content"
  29.  
  30.        android:layout_height="wrap_content"
  31.  
  32.        android:layout_below="@id/im1"
  33.  
  34.        android:layout_alignParentLeft="true"
  35.  
  36.        android:layout_alignParentTop="true"
  37.  
  38.        android:background="@drawable/open"              
  39.  
  40.     />
  41.  
  42.      <Button
  43.  
  44.        android:id="@+id/exit"
  45.  
  46.        android:layout_width="wrap_content"
  47.  
  48.        android:layout_height="wrap_content"
  49.  
  50.        android:layout_alignParentRight="true"
  51.  
  52.        android:layout_alignParentTop="true"        
  53.  
  54.        android:layout_below="@id/im1"
  55.  
  56.        android:background="@drawable/quit"                    
  57.  
  58.     />
  59.  
  60.     <ImageView
  61.  
  62.         android:id="@+id/panel"
  63.  
  64.         android:layout_width="wrap_content"
  65.  
  66.         android:layout_height="wrap_content"
  67.  
  68.         android:layout_below="@id/im1"
  69.  
  70.         android:layout_centerHorizontal = "true"
  71.  
  72.         android:layout_alignLeft="@id/open"
  73.  
  74.         android:layout_alignRight="@id/exit"
  75.  
  76.         android:scaleType ="fitXY"
  77.  
  78.         android:adjustViewBounds="true"/>    
  79.  
  80. </RelativeLayout>
Parsed in 0.005 seconds, using GeSHi 1.0.8.4
Bear
Junior Developer
Junior Developer
 
Posts: 15
Joined: Fri Jan 22, 2010 3:50 pm

Postby Bear » Thu Jan 28, 2010 11:05 am

So, it seems that i have what i want. Another question - how can I resize controls? I want to change sizes of buttons, imageviews etc
Bear
Junior Developer
Junior Developer
 
Posts: 15
Joined: Fri Jan 22, 2010 3:50 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 7 guests