简体   繁体   中英

Android Horizontal orientation while rotation some parts missing

I am currently working on a application .when i installed my_app in android mobile while rotating in horizontal view my buttons are missing,please help!! Thanks in advance My java coding is:

public class Draw extends Activity {
     ImageView iv1;
    @Override   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final DrawView drawView = new DrawView(this);
        setContentView(R.layout.draw);
        FrameLayout frm_layout=(FrameLayout) findViewById(R.id.main_frame);
        iv1=(ImageView) findViewById(R.id.imageView1);
        frm_layout.addView(drawView);

        Intent myIntent = getIntent(); // this is just for example purpose
        String test=myIntent.getExtras().getString("guided");
        if(test.equals("1"))
        {
            iv1.setImageResource(R.drawable.untitled);

            iv1.setAlpha(100);
        }
        else
        {
            //iv1.setImageResource(null);
        }
        //Toast.makeText(getApplicationContext(), test.toString(), 2000).show();


        Button btn_undo=(Button) findViewById(R.id.button1);
        btn_undo.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                drawView.onClickUndo();
            }
        });

        Button btn_redo=(Button) findViewById(R.id.button2);
        btn_redo.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                drawView.onClickRedo();
            }
        });
    }

}

My XML coding is below:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@android:color/white" >
 <FrameLayout
     android:id="@+id/main_frame"
     android:layout_width="fill_parent"
     android:layout_height="472dp"
     android:background="@android:color/white" >

    <ImageView
         android:id="@+id/imageView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
          /> 

 </FrameLayout>
 <RelativeLayout
     android:id="@+id/relativeLayout1"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
       >
     <Button
         android:id="@+id/button2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
         android:layout_alignParentTop="true"
         android:layout_centerHorizontal="true"
         android:text="Redo" />
     <Button
         android:id="@+id/button1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
         android:layout_alignParentLeft="true"
         android:layout_alignParentTop="true"
         android:text="Undo" />
     <Button
         android:id="@+id/button3"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentBottom="true"
         android:layout_alignParentRight="true"
         android:layout_alignParentTop="true"
         android:text="Save" />
 </RelativeLayout>
</LinearLayout>

do one thing make a folder named Layout-land in res folder , in which put your xml file. now you can design your xml in horizontal mode . do whatever changes you want in that file and check :

otw put a scroll bar in whole layout and then check :) good luck

Just Copy and Past in you xml file, it wil run completely. I have tested.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@android:color/white" >
<FrameLayout
 android:id="@+id/main_frame"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="@android:color/white" android:layout_weight="0.1">

<ImageView
     android:id="@+id/imageView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
      /> 

</FrameLayout>
<RelativeLayout
 android:id="@+id/relativeLayout1"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
   android:layout_weight="0.9" android:layout_gravity="bottom" android:layout_marginTop="-10dp">
 <Button
     android:id="@+id/button2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentTop="true"
     android:layout_centerHorizontal="true"
     android:text="Redo" />
 <Button
     android:id="@+id/button1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentLeft="true"
     android:layout_alignParentTop="true"
     android:text="Undo" />
 <Button
     android:id="@+id/button3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_alignParentRight="true"
     android:layout_alignParentTop="true"
     android:text="Save" />
 </RelativeLayout>
</LinearLayout>

Hope this is what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM