有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

键盘打开时的java滚动活动页面

我希望当软键板打开时,活动页面会滚动

为此,我添加了xml中的滚动视图

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:tools="http://schemas.安卓.com/tools"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"

    tools:context="com.example.trying.MainActivity" 
    >


    <ScrollView
        安卓:id="@+id/scrollView1"
        安卓:layout_width="match_parent"
        安卓:layout_height="match_parent"
         >

        <RelativeLayout
            安卓:id="@+id/LayoutBackground"
            安卓:layout_width="match_parent"
            安卓:layout_height="match_parent"
            安卓:orientation="vertical"
             安卓:background="@drawable/background" 
           >

            <EditText
                安卓:layout_width="wrap_content"
                安卓:layout_height="wrap_content"
                安卓:text="@string/hello_world" >

              <requestFocus />
           </EditText>
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

并更改了代码中的realativeLayout高度:

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

         Display display = getWindowManager().getDefaultDisplay();
         Point size = new Point();
         display.getSize(size);
         int height = size.y;

         int x=getActionBarHeight();//in this line I get the actionBar height programicaly the function is in the end of page


         RelativeLayout l= (RelativeLayout)findViewById(R.id.LayoutBackground);
         l.getLayoutParams().height = (height-x);//the layout size = size of full screen - size of actionBar




    }

    //I saw this function in stackOverflow site. function to get the actionBar height
    public int getActionBarHeight() {

            TypedValue tv = new TypedValue();
            getApplicationContext().getTheme().resolveAttribute(安卓.R.attr.actionBarSize, tv, true);
            int actionBarHeight = getResources().getDimensionPixelSize(tv.resourceId);
            return actionBarHeight;
        }

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    package="com.example.trying"
    安卓:versionCode="1"
    安卓:versionName="1.0" >

    <uses-sdk
        安卓:minSdkVersion="16"
        安卓:targetSdkVersion="21" />

    <application
        安卓:allowBackup="true"
        安卓:icon="@drawable/ic_launcher"
        安卓:label="@string/app_name"
        安卓:theme="@style/AppTheme" >
        <activity
            安卓:name=".MainActivity"
            安卓:label="@string/app_name" 
             安卓:windowSoftInputMode="stateHidden" >
            <intent-filter>
                <action 安卓:name="安卓.intent.action.MAIN" />

                <category 安卓:name="安卓.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

idia认为布局高度取决于屏幕大小(所有设备)和操作栏高度

我的问题是,当我运行应用程序时,背景很小。 动作条的大小似乎下降了两倍


共 (1) 个答案

  1. # 1 楼答案

    您不需要在布局中添加ScrollView。将其从xml中删除。然后在AndroidManifest中。xml,在活动中添加以下行:

    <activity
            android:name=".MainActivity"
            android:label="@string/app_name" 
              android:configChanges="keyboardHidden"
            android:windowSoftInputMode="adjustPan|stateAlwaysHidden" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>