简体   繁体   English

Android更改屏幕旋转

[英]Android Change rotation of screen

Hello I am having a problem when the screen is normal the image looks okay on the android phone but when i shift to landscape it occupy the space of the Navigation header bar. 您好,当屏幕正常时,Android手机上的图像看起来还不错,但是当我转向横向时,它占据了导航标题栏的空间。 Also when i rotate phone it takes me back to the home or Main Activity i don't what that. 另外,当我旋转手机时,它会将我带回家庭或主要活动,但我却没有。 the following is the Main-fragment.XML 以下是Main-fragment.XML

<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>

MAnifest.XML 多媒体文件

<?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>

The following is the MainFragment.java 以下是MainFragment.java

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);
    }

}

Potrait图片

Potrait

I think that you don't have defined the Toolbar to your Fragment , and you don't know how and when use Fragment . 我认为您尚未为Fragment定义Toolbar ,并且您不知道如何以及何时使用Fragment I suggest you to Download Android studio (if you had it, update SDK and IDE at last version). 我建议您下载Android studio(如果有的话,请在最新版本中更新SDK和IDE)。

After that crete a new project with Blank Activity and start you project from there. 之后,创建一个包含Blank Activity的新项目,然后从那里开始您的项目。

After if you want/need, you can add 1,2 or N Fragments to your Activity . 之后,如果需要,可以将1,2或N个Fragments添加到Activity

I Suggest you to read the official documents that i link to you below: 我建议您阅读下面链接到您的官方文件:

Build your first app 构建您的第一个应用

Activitys 活动项目

Fragments 碎片

Build dynamic UI with Fragments 使用片段构建动态UI

If you read this Documents you have the basic for start your App and you can see that the problem that you have disappear. 如果您阅读本文档,则具有启动应用程序的基本知识,并且可以看到问题已经消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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