1

look at my picture I want to design layout like that. look at my XML code below, I already design it but when I rotate it to landscape, the button is not fit the shop area(short) and linear layout in image price area is out of boundary(longer). I want it fit all orientation.why I am using button? because when I pragmatically, I can use it as onClickListener

  1. how can I design this layout for fit all orientation?

  2. Have any way to design this layout using XML code (not use background image)

enter image description here

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@drawable/bar_all"
    android:gravity="center_vertical"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <Button
            android:id="@+id/btn_all"
            android:layout_width="265dp"
            android:layout_height="match_parent"
            android:background="#00000000" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:orientation="vertical" >

            <ImageButton
                android:id="@+id/btn_ic_mypage"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="right"
                android:layout_marginRight="12dp"
                android:background="#00000000"
                android:scaleType="fitXY"
                android:src="@drawable/icon_mypage" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>
  1. Linear Layout for place backgroud image
  2. Linear Layout for put button cover the shop area. easy coding onClickListener
  3. Linea Layout for cover $ image area and put the image area.
kongkea
  • 9,788
  • 12
  • 39
  • 49
  • To answer your "all orientation part" of your question, make separate layouts for the orientation. As long as the xmls have the same name, android will auto-switch between them upon orientation change. http://stackoverflow.com/questions/5407752/android-layout-folders-layout-layout-port-layout-land – A--C Dec 06 '12 at 01:29
  • but it can't fit all screen size phone. – kongkea Dec 06 '12 at 01:31
  • Which is why you should consider reading [this.](http://developer.android.com/guide/practices/screens_support.html "this.") The android res folder also supports many screen sizes. – A--C Dec 06 '12 at 01:34
  • have any way to design this layout that not use background image – kongkea Dec 06 '12 at 01:40

1 Answers1

2

here is the code what you looking for..

Also PL make sure you should avoid any length, height, width value is 20 dp,13 dp etc

This code will be fit for all screen sizes.

main.xml

   <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="top">
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/background_main"
        android:gravity="right|center_vertical">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/linearLayout3"
            android:orientation="vertical"
            android:layout_weight="1"
            android:gravity="center">
            <Button
                android:layout_height="match_parent"
                android:id="@+id/button_shop"
                android:layout_width="match_parent"
                android:background="@null"></Button>
        </LinearLayout>
        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:gravity="center">
            <Button
                android:background="@drawable/button"
                android:id="@+id/button_doller"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"></Button>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

MainActivity.java

public class MainActivity extends Activity implements OnClickListener {

    private Button btnShop = null;
    private Button btnDoller = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btnShop = (Button) findViewById(R.id.button_shop);
        btnShop.setOnClickListener(this);

        btnDoller = (Button) findViewById(R.id.button_doller);
        btnDoller.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if (btnShop == v) {
            Toast.makeText(this, "shop button clicked", Toast.LENGTH_LONG)
                    .show();
        } else if (btnDoller == v) {
            Toast.makeText(this, "doller button clicked", Toast.LENGTH_LONG)
                    .show();
        }

    }
}

PS : if you get image small then create bigger image size icon, i have just used dummy only.

Hope it helps!!

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
  • yeah, it work find. but when setOnClickListener to linearlayout1 to make toast, and then I click to linearlayout2 it show toast as well even if it cover linearlayout1. how about that? actualy I don't want area around $ image do anything. @RDC – kongkea Dec 07 '12 at 01:10
  • this isn't what I want but it bring me success. – kongkea Dec 07 '12 at 07:32
  • @kongkea sorry may be I couldn't get you properly,but I was trying best to solve your problem, anyway now you did it.. cheers :) – swiftBoy Dec 07 '12 at 07:39