当我旋转移动活动屏幕不旋转当我、屏幕

由网友(像温柔野兽)分享简介:我已经使用这个code作为@gnobal张贴在 http://stackoverflow.com/a/2700683/1556329 和它的伟大工程。但我的问题是,我发现,当我申请Theme.Transparent的活动不进入横向模式,当我旋转手机。I have used this code as @gnobal p...

我已经使用这个code作为@gnobal张贴在 http://stackoverflow.com/a/2700683/1556329 和它的伟大工程。但我的问题是,我发现,当我申请Theme.Transparent的活动不进入横向模式,当我旋转手机。

I have used this code as @gnobal posted on http://stackoverflow.com/a/2700683/1556329 and it works great. But my issue is that I have found that when I apply Theme.Transparent the activity does not goes to landscape mode when I rotate the mobile phone.

主题:

 <style name="Theme.Transparent" parent="android:Theme.Dialog">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
  </style>

布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/layoutImagen"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical"
    android:windowContentOverlay="@null"
    android:windowNoTitle="true"
    tools:context=".ImagenExamen_activity" >

<!--     android:background="#CC000000" -->
<!--     android:backgroundDimEnabled="true" -->

    <ImageView
        android:id="@+id/imageViewImagen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

</LinearLayout>

活动:

import android.app.Activity;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.meapp.Utilities;

public class Imagen_activity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_imagen_examen);

        Bundle b = getIntent().getExtras();
        String imagen = b.getString("imagen_name");
        int id = getResources().getIdentifier(imagen, "drawable", getPackageName());

        ImageView imageView = (ImageView) findViewById(R.id.imageViewImagen);


        // Determinacion tamaño fuente
        BitmapFactory.Options bitmapOpt = new BitmapFactory.Options();
        bitmapOpt.inJustDecodeBounds = true;
        BitmapFactory.decodeResource(getResources(), id, bitmapOpt);

        int[] screen_dim = Utilites.verDimensionesPantalla(this);


                // más eficiente si se usa una potencia de 2
        imageView.setImageBitmap(Utilities
                .decodeSampledBitmapFromResource(getResources(), id,
                        screen_dim[0], screen_dim[1], true));



        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                cerrarImagen();
            }
        }); 


    }

    public void cerrarImagen() {
        ((Activity) this).finish();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.imagen_examen_, menu);
        return true;
    }

}

为什么不能被旋转?我试图windowIsFloating更改为false,并更改其它参数没有运气。

Why can't it be rotating? I have tried to change windowIsFloating to false, and change other parameters without luck.

推荐答案

您可以检查出这个

             android:screenOrientation="sensor"
or 
             android:screenOrientation="user" 

添加其中一个到你的清单&LT;活动.............. /&GT; 。 不要忘了把它添加到您的清单应用程序,以避免重新创建活动安卓configChanges =keyboardHidden |方向|屏幕尺寸

add one of them to your manifest <activity............../>. and don't forget to add this to your application in manifest as well to avoid recreating your activity android:configChanges="keyboardHidden|orientation|screenSize"

阅读全文

相关推荐

最新文章