0

Hi i have a linear layout and i want to show my custom view only horizontal but it just does not work why?i have the xml like that:

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_height="wrap_content"
  android:layout_width="fill_parent" 
  android:orientation="horizontal" 
  android:scrollbars="horizontal" 
  android:id="@+id/ll"
  android:background="@drawable/horizon">

but i add custom view on it so maybe there should i set some attributes but i do not know which.

MyView mView = new MyView(this,i);
realViewSwitcher.addView(mView);

myView.java:

public class MyView extends View {

    public MyView(Context context, int kolki) {
        super(context);

        if (kolki == 0){
            this.setBackgroundResource(R.drawable.distspeed);
        }
        if (kolki == 1){
            this.setBackgroundResource(R.drawable.hxmdist);
        }
    }

    public void setBackgroundResource (int resid){
        super.setBackgroundResource(resid);
    } 

    public void onDraw(Canvas c){
        super.onDraw(c);
        Paint paint = new Paint();
        Path path = new Path();
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.TRANSPARENT);
        c.drawPaint(paint);
        for (int i = 50; i < 100; i++) {
               path.moveTo(i, i-1);
               path.lineTo(i, i);  
        }
        path.close();
        paint.setStrokeWidth(3);
        paint.setPathEffect(null);
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.STROKE);
        c.drawPath(path, paint);
    }

}

thanks

i mean somethink like angry birds when you start app it flip to horizontal mode and does not flip back while the game is running, i need exactly the same thing.it should retain in landscape mode while the activity is running

Csabi
  • 3,097
  • 17
  • 59
  • 107

2 Answers2

1

If you want an extra Layout XML-File for the Landscape mode, you can put those Layouts in the res/layout-land-Folder, see here.

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
  • it does not let compile the program [2011-05-16 14:12:28 - TabbedHorizontalPagerDemo] (skipping index file 'C:\Users\Bladeszasza\workspace\TabbedHorizontalPagerDemo\res\drawable-hdpi\Thumbs.db') [2011-05-16 14:12:28 - TabbedHorizontalPagerDemo] invalid resource directory name: C:\Users\Bladeszasza\workspace\TabbedHorizontalPagerDemo\res/layout_land – Csabi May 16 '11 at 12:14
  • You do realize that the "/"-Shlash was a path-seperator? So it's the "layout-land" Folder in your "res"-Folder. Also, the Thumbs.db is created when you use the Windows Explorer to get a preview on your picture. This File can be deleted. – Lukas Knuth May 16 '11 at 12:25
  • I do not understand what you mean sorry – Csabi May 16 '11 at 12:27
  • Put the Layout which should be shown when you turn your Device in Landscape mode in your "Layout-Land"-Folder in the (already existing) "res"-Folder. – Lukas Knuth May 16 '11 at 12:29
  • I did that and it show me the same error, but i was need to make layout_land folder in the res folder because it do not contains it. – Csabi May 16 '11 at 12:32
  • Yes, it's not created by default. Also try to delete the Thumbs.db File. – Lukas Knuth May 16 '11 at 12:34
  • Above you said "if i create layout_land folder", the folder needs to be "layout-land". – Lukas Knuth May 16 '11 at 12:37
0

Do you mean you need to restrict orientation to horizontal?

How do you create an app that only allows horizontal orientation?

In your application's manifest file, within the application tag, put android:screenOrientation="landscape"

Community
  • 1
  • 1
Jodes
  • 14,118
  • 26
  • 97
  • 156