Android改变屏幕的旋转
您好,我有一个问题,当屏幕正常时,android手机上的图像看起来不错,但当我切换到横向时,它会占用导航标题栏的空间。 而且,当我旋转手机时,它会带我回到家中或主要活动,我不知道这是什么。以下是Main-fragment.XMLAndroid改变屏幕的旋转,android,android-layout,Android,Android Layout,您好,我有一个问题,当屏幕正常时,android手机上的图像看起来不错,但当我切换到横向时,它会占用导航标题栏的空间。 而且,当我旋转手机时,它会带我回到家中或主要活动,我不知道这是什么。以下是Main-fragment.XML <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" andr
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.fred.yeno.MainFragment">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/puAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/dice" />
</LinearLayout>
</LinearLayout>
我认为您没有为您的
片段定义工具栏
,您也不知道如何以及何时使用片段
。
我建议您下载Android studio(如果有,请在上一版本更新SDK和IDE)
在此之后,创建一个新项目,其中包含空白活动
,并从那里开始您的项目
如果您愿意/需要,可以在活动中添加1,2或N个片段
我建议您阅读以下我链接到您的官方文件:
如果您阅读了这些文档,您就有了启动应用程序的基本方法,您可以看到您的问题已经消失。您可以将横向布局的代码放入程序中吗?您想消除旋转的可能性吗?还是怎样添加片段的代码可能您在工具栏声明或其他方面有错误,与片段xml相同。当旋转屏幕时,活动将重新创建。不应该旋转,但应保持我导航到的页面,而不是指向主片段。您可以发布更多代码吗?我有一个应用程序,在工具栏上有一个带有选项卡的视图寻呼机,如果我旋转屏幕纵向风景,反之亦然,屏幕焦点仍然保持在同一个片段中,我有5个具有此布局的片段。您如何在清单中声明片段?你增加了一些父母关系吗?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fred.yeu">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
package com.example.fred.yenu;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A simple {@link Fragment} subclass.
*/
public class MainFragment extends Fragment {
public MainFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_main, container, false);
}
}