请教一下横屏显示的问题

android 手机横屏左侧出来一个竖条的地方没有覆盖到,显示的是桌面,这个竖条的跨度大概和标题栏差不多,请问怎样才能让activit占满整个屏幕,

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

 getWindow().getInsetsController().hide(WindowInsets.Type.statusBars());

这些都加了

在 AndroidManifest.xml 文件中为你的 Activity 添加以下属性:

<activity
    android:name=".YourActivity"
    android:screenOrientation="landscape"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>


确认你的布局文件中没有设置固定的宽度和高度。如果设置了固定的宽度和高度,可能会导致布局在不同的设备上显示不完整。可以将布局文件中的宽度和高度属性改为 match_parent,让布局自适应屏幕。

确认你的 Activity 中没有设置 padding、margin 或者其他的偏移量。这些偏移量也可能导致布局显示不完整。可以将这些偏移量设置为 0,让布局与屏幕边缘对齐。

如果以上步骤都无法解决问题,可以尝试在 Activity 的 onCreate() 方法中调用 setContentView() 方法,并传入一个布局文件的 ID,例如

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);  // 将布局文件设置为 Activity 的内容视图
}


感觉像虚拟导航键引起的,你在系统设置里面尝试关闭、打开虚拟导航键试试。

  • 你可以看下这个问题的回答https://ask.csdn.net/questions/355642
  • 除此之外, 这篇博客: Android 应用开发:注册信息界面中的 这还有一个点,书上没有。就是新建的activty要在AndroidManifest.xml文件中注册。 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 要添加注册代码,或者在设置里进行注册。
    三种方式选一个即可!!!!!!!

    <activity android:name=".ResultActivity"/>
    <activity android:name=".ResultActivity"></activity>
    <activity android:name="com.....ResultActivity" android:label="@string/app_name" ></activity>
    

    在这里插入图片描述


    代码部分:
    这部分为系统自动生成代码。

    //这里附录activity_main.xml,文件代码
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.example.dn.zxyapplication_02.MainActivity">
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true"
            android:weightSum="1">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="用户名"
                android:id="@+id/textView"
                android:textColor="#000000" />
    
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPersonName"
                android:ems="10"
                android:id="@+id/name" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="密码"
                android:id="@+id/textView2"
                android:textColor="#000000" />
    
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:ems="10"
                android:id="@+id/password" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="性别"
                android:id="@+id/textView3"
                android:textColor="#000000" />
                
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
    
                <RadioGroup
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/sex">
    
                <RadioButton
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:text="男"
                    android:id="@+id/man"
                    android:checked="true" />
    
                <RadioButton
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:text="女"
                    android:id="@+id/woman"
                    android:checked="false" />
                </RadioGroup>
            </TableRow>
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="联系电话"
                android:id="@+id/textView4"
                android:textColor="#000000" />
    
            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="phone"
                android:ems="10"
                android:id="@+id/phone"
                android:onClick="myclick"
                android:nestedScrollingEnabled="true" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="部门"
                android:id="@+id/textView5"
                android:textColor="#000000" />
    
            <Spinner
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/dept"
                android:entries="@array/dept"
                android:layout_weight="0.17" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="爱好"
                android:id="@+id/textView6"
                android:textColor="#000000" />
    
            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="myclick"
                android:nestedScrollingEnabled="false">
    
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="书籍"
                    android:id="@+id/book"
                    android:checked="false" />
    
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="运动"
                    android:id="@+id/sport"
                    android:checked="false" />
    
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="音乐"
                    android:id="@+id/music"
                    android:checked="false" />
    
                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="电影"
                    android:id="@+id/movie"
                    android:checked="false" />
    
            </TableRow>
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="确定"
                android:id="@+id/ok"
                android:onClick="myclick"
                android:layout_gravity="center_horizontal" />
    
        </LinearLayout>
    </RelativeLayout>
    
    

    1.这个部分是主后台程序。MainActivity.java

    //MainActivity.java
    package com.example.dn.zxyapplication_02;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    
    import android.os.Bundle;
    import android.text.Editable;
    import android.util.Log;
    import android.view.View;
    import android.view.Window;
    import android.widget.CheckBox;
    import android.widget.EditText;
    import android.widget.RadioButton;
    import android.widget.RadioGroup;
    import android.widget.Spinner;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import java.util.ArrayList;
    
    
    public class
            MainActivity extends AppCompatActivity {
    
        public MainActivity() {
    
    
        }
    
        private ArrayList<CheckBox> favs;                //定义一个存放爱好中复选框的对象favs
        private EditText NAME;                          // 布局各组件对象
        private EditText PASSWORD;
        private EditText PHONE;
        private Spinner DEPT;
        private RadioGroup SEX;
        private RadioButton MAN;
        private RadioButton WOMAN;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            //获取个组件对象
            NAME=(EditText)findViewById(R.id.name);
            PASSWORD=(EditText)findViewById(R.id.password);
            PHONE=(EditText)findViewById(R.id.phone);
            SEX=(RadioGroup)findViewById(R.id.sex);
            DEPT=(Spinner)findViewById(R.id.dept);
            MAN=(RadioButton)findViewById(R.id.man);
            WOMAN=(RadioButton)findViewById(R.id.woman);
            favs=new ArrayList<CheckBox>();
            CheckBox book=(CheckBox) findViewById(R.id.book);
            CheckBox sport=(CheckBox) findViewById(R.id.sport);
            CheckBox music=(CheckBox) findViewById(R.id.music);
            CheckBox movie=(CheckBox) findViewById(R.id.movie);
            favs.add(book);
            favs.add(sport);
            favs.add(music);
            favs.add(movie);
    
        }
    
    
    
        public String getSex(){
            RadioButton radioButton= (RadioButton)findViewById(SEX.getCheckedRadioButtonId());
            if(radioButton!=null) {
                return radioButton.getText().toString();
            }else {
                return "Not Selected";
            }
        }
    
        public String getFavorite()
        {
            String favo="";
            for(CheckBox cb:favs){
                if(cb.isChecked()){
                    favo+=cb.getText().toString();
                    favo+=",";
                }
            }
            if(!"".equals(favo))
                favo=favo.substring(0,favo.length()-1);
            else
                favo="您未选择爱好!";
            return favo;
        }
    
        public void myclick(View view){
            //if (true){
            StringBuilder sb =new StringBuilder();
            sb.append("用户名: "+NAME.getText().toString()+"\n");
            Log.v("name", "done");
            sb.append("性别: " + getSex() + "\n");
            Log.v("sex", "done");
            sb.append("电话: "+PHONE.getText().toString()+"\n");
            Log.v("tel","done");
            sb.append("部门: "+DEPT.getSelectedItem().toString()+"\n");
            Log.v("part","done");
            sb.append("爱好: "+getFavorite()+"\n");
            Log.v("fav","done");
            Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show();
            // Toast.makeText(this, "Test", Toast.LENGTH_LONG).show();
    
           Intent intent = new Intent();
            intent.setClass(this, ResultActivity.class);
            intent.putExtra("info", sb.toString());
            this.startActivity(intent);
            //}
        }
    
    }
    
    

    2.结果展示的后台程序。ResultActivity.java

    //ResultActivity.java
    package com.example.dn.zxyapplication_02;
    
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.Window;
    import android.widget.TextView;
    
    /**
     * Created by DN on 2020/3/30.
     */
    
    
    public class ResultActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            requestWindowFeature(Window.FEATURE_NO_TITLE);
    
            setContentView(R.layout.activity_result);
    
            TextView result = (TextView) findViewById(R.id.result);
    
            result.setText("从前一页面传来如下:\n\n" + this.getIntent().getStringExtra("info"));
    
        }
    }
    
    

    3.自动生成的xml布局文件。(里面只有一个TextView控件)activity_result.xml

    //activity_result.xml
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:id="@+id/result"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
            
    </LinearLayout>
    

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632