我尝试了<条码>植被分布()以获得取向价值,但总是回报。 页: 1
I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...
我尝试了<条码>植被分布()以获得取向价值,但总是回报。 页: 1
方向有所改观,但这并不是你问题的根源。 确实,你应使用getRotation()而不是getOrientation(<>/strong>),但只有您的甲型六氯环己烷(API 8级)或更高,才能使用。 有些人甚至谷歌者有时似乎忘记了这一点。
举例来说,在我的HTC愿望下,getOrientation()和getRotation()都报告了同样的价值:
当你“头盔”时,没有报告(第180段,即价值2)。 这一结果可能是针对具体装置的。
首先,如果你使用 em子或装置,你应当表明。 你们是否知道如何轮换支持者? 然后,我建议设立一个小型测试方案,由一线Create(Create)组成。 类似方法:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display mDisplay = mWindowManager.getDefaultDisplay();
Log.d("ORIENTATION_TEST", "getOrientation(): " + mDisplay.getOrientation());
}
Check if the screen of your your device has been locked in the device settings Settings > Display > Auto-Rotate Screen. If that checkbox is unchecked, Android will not report orientation changes to your Activity. To be clear: it will not restart the activity. In my case I get only 0, like you described.
如果你在<<>onCreate()上添加这些内容,你可以从你的方案中检查。
int sysAutoRotate = 0;
try {
sysAutoRotate = Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION);
} catch (SettingNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("ORIENTATION_TEST", "Auto-rotate Screen from Device Settings:" + sysAutoRotate);
It will return 0 if Auto-Rotate is off and 1 if Auto-Rotate is on. Another try. In your original program you might have set in manifest
android:screenOrientation="portrait"
效果好,但这只是你的活动。 如果你提出小型测试方案,就会消除这一档案(这是我建议的原因)。
说明: 整个方向/轮换专题的确是一个“利益”专题。 试采、使用Log.d(),学习。
如果你想要知道目前所展示的内容是地貌或孔隙(可能完全独立于电话的实物轮换),你可以使用:
http://developer.android.com/vis/android/content/res/Configuration.html#orientation”rel=“noreferer”>Developer Documentation
public int orientation
Since: API Level 1
Overall orientation of the screen. May be one of ORIENTATION_LANDSCAPE, ORIENTATION_PORTRAIT, or ORIENTATION_SQUARE.
getRotation(
。
为避免使用陈旧方法,发现。 该公司自APIC lvl 1号运行以来,仍在使用最新的海底设备。 (未解释)
举例来说,考虑到以下法典:
Configuration config = getResources().getConfiguration();
if (config.orientation == Configuration.ORIENTATION_PORTRAIT)
{
setContentView(R.layout.portraitStart);
}
else
{
setContentView(R.layout.landscapeStart);
}
最好的希望是,这一答案有助于任何人进入。
/* First, get the Display from the WindowManager */
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
/* Now we can retrieve all display-related infos */
int width = display.getWidth();
int height = display.getHeight();
int orientation = display.getOrientation();
I think you need to create two different layouts and inflate different layouts on different orientation. I am giving you a sample code which is working fine for me. "context" you can pass from your activity in case of custom adapter. If you are using custom adapter then you can try this code:
@Override
public View getView(final int position,
View convertView,
ViewGroup parent)
{
View rowView = convertView;
ViewHolder holder = null;
int i = context.getResources().getConfiguration().orientation;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (i == Configuration.ORIENTATION_PORTRAIT) {
rowView = inflater.inflate(R.layout.protrait_layout, null, false);
} else {
rowView = inflater.inflate(R.layout.landscape_layout, null, false);
}
holder = new ViewHolder();
holder.button = (Button) rowView.findViewById(R.id.button1);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
return rowView;
}
你们可以直接在你们的法典中规定两个不同的规定。
int i = context.getResources().getConfiguration().orientation;
if (i == Configuration.ORIENTATION_PORTRAIT) {
ArrayAdapter<String> adt = new ArrayAdapter<String>(getApplicationContext(), R.layout.protrait_layout, name);
} else {
ArrayAdapter<String> adt = new ArrayAdapter<String>(getApplicationContext(), R.layout.landscape_layout, name);
}
在Nexus One SDK 2.3问题上,我也存在同样的问题。
解决办法是:CheckOrient on Anders 。
I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...
I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...
I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...
I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...
To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?
When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...
I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...
I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...