android - 安卓activity无法填充屏幕
PHP中文网
PHP中文网 2017-04-18 09:07:32
0
3
485

新手在开发安卓的过程中遇到了一些问题,在activity的四周总有去不掉的白边 ,activity是没有填满屏幕的,xml里的设置是macthparent没错,不知道问题出在哪里,

补充一下这个界面的xml代码

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_log_in"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:background="#ffffff"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.administrator.productiontoolforpda.Activity_logIn">=
<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/login"/>

<LinearLayout

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_x="0dp"
android:layout_y="240dp">
<EditText
    android:layout_width="200dp"
    android:layout_height="35dp"
    android:autoLink="all"
    android:hint="用户名"
    android:inputType="textPersonName"
    android:ems="10"
    android:layout_x="90dp"
    android:layout_y="112dp"
    android:id="@+id/account"
    android:textSize="14sp"
    android:text="" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_x="0dp"
    android:layout_y="290dp">
    <EditText
        android:layout_width="200dp"
        android:layout_height="35dp"
        android:inputType="textPassword"
        android:ems="10"
        android:hint="密码"
        android:layout_x="90dp"
        android:layout_y="152dp"
        android:id="@+id/password"
        android:text=""
        android:textSize="14sp" />
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_x="0dp"
    android:layout_y="340dp"
    android:orientation="vertical"  >

    <Button
        android:text="确认"
        android:background="@drawable/textview_round_border_blue"
        android:textColor="#ffffff"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_x="25dp"
        android:layout_y="220dp"
        android:id="@+id/ok"
        style="@android:style/Widget.Button"
        android:layout_weight="1" />

    <Button
        android:text="取消"
        android:background="@drawable/textview_round_border_blue"
        android:layout_width="match_parent"
        android:textColor="#ffffff"
        android:layout_height="50dp"
        android:layout_x="175dp"
        android:layout_y="220dp"
        android:id="@+id/cancel"
        style="@android:style/Widget.Button"
        android:layout_weight="1" />
</LinearLayout>

</AbsoluteLayout>

java代码

package com.example.administrator.productiontoolforpda;

import android.app.Activity;
import android.app.Dialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;

import java.sql.Date;
import java.text.SimpleDateFormat;

import static com.example.administrator.productiontoolforpda.myApplication.getContext;

public class Activity_logIn extends Dialog {

private EditText account;
private HttpInfo httpInfo;
private EditText password;
private Button ok;
private Button cancel;
private DBHelper dbHelper ;
public static String VERSION = "v1.0";
public  String DEVICE_ID;
public Activity_logIn(Context context){
    super(context,R.style.PopupDialog);

// }

//protected void onCreate(Bundle savedInstanceState) {
   // super.onCreate(savedInstanceState);
    Window win = this.getWindow();
    win.setGravity(Gravity.BOTTOM);                       //从下方弹出
    win.getDecorView().setPadding(0, 0, 0, 0);
    WindowManager.LayoutParams lp = win.getAttributes();
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;   //宽度填满
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;  //高度自适应
    win.setAttributes(lp);
    super.setContentView(R.layout.activity_log_in);
    account = (EditText)findViewById(R.id.account);
    password = (EditText)findViewById(R.id.password);
    ok = (Button)findViewById(R.id.ok);
    cancel = (Button)findViewById(R.id.cancel);
    TelephonyManager tm = (TelephonyManager)myApplication.getContext().getSystemService(Context.TELEPHONY_SERVICE);
    DEVICE_ID = tm.getDeviceId();
    httpInfo = new HttpInfo();
    dbHelper = new DBHelper(myApplication.getContext());
    //填充登陆账号和密码
    InputUserInfo();
    ok.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String username = account.getText().toString();
            String p = password.getText().toString();
            ContentValues values = new ContentValues();
            //new newThread().start(); //申请产线列表
            httpInfo.lineTest();
            values.put("username",username);
            values.put("password",p);
            dbHelper.deleteFormUser();
            dbHelper.insertIntoUser(values);
            //写入产线信息
            Activity_logIn.this.dismiss();

        }
    });
    cancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Activity_logIn.this.dismiss();
        }
    });
}
//测试滚动bar
public void insertLineInfo(){
    for(int i = 0;i<5;i++){
        ContentValues values2 = new ContentValues();
        values2.put("lineNum","未设置产线"+i);
        dbHelper.insertIntoLineNum(values2);
    }
}
public void InputUserInfo(){
    Cursor c = dbHelper.queryFromUser();
    if(c.moveToFirst()) {
        account.setText(c.getString(1));
        password.setText(c.getString(2));
    }
}
class newThread extends Thread{
    public void run(){
        String username = account.getText().toString();
        String pw = password.getText().toString();
        Message msg = new Message();
        try {
            httpInfo.getInfoFromWeb(username, pw, DEVICE_ID);
        }catch (Exception e) {
            Log.e("eeeeeeeee",e.toString());
        }
        if(httpInfo.status=="0"){
            httpInfo.updataLineNum();
            msg.what = 0;
            mHandler.sendMessage(msg);
            Intent i = new Intent(myApplication.getContext(),Activity_setLineNum.class);
            myApplication.getContext().startActivity(i);
            Activity_logIn.this.dismiss();
        }
        else {
            msg.what = 1;
            mHandler.sendMessage(msg);
        }
    }
}
private Handler mHandler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        switch (msg.what) {
            case 0:
                Toast.makeText(getContext(), "登陆成功", Toast.LENGTH_SHORT).show();
                break;
            case 1:
                Toast.makeText(getContext(), httpInfo.message, Toast.LENGTH_SHORT).show();
                break;
        }
    }
};

}

PHP中文网
PHP中文网

认证0级讲师

répondre à tous(3)
PHPzhong

À l'intérieur du premier fichier XML

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

Le rembourrage est défini ici, supprimez-le simplement

迷茫

Publiez le code de mise en page et apprenez à poser des questions. Personne ne saura exactement où se trouve votre problème. Je ne peux qu'estimer que votre fichier XML de mise en page conserve la valeur de remplissage lorsqu'il est généré automatiquement.

大家讲道理

La bonne réponse à l'étage est probablement soit margin, soit padding

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal