android - 安卓activity無法填充屏幕
問題描述
新手在開發(fā)安卓的過程中遇到了一些問題,在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: 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'> <EditTextandroid:layout_width='200dp'android:layout_height='35dp'android:inputType='textPassword'android:ems='10'android:hint='密碼'android:layout_x='90dp'android:layout_y='152dp'android: 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' > <Buttonandroid: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: android:layout_weight='1' /> <Buttonandroid: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: 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() {@Overridepublic 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() {@Overridepublic void onClick(View v) { Activity_logIn.this.dismiss();} });}//測試滾動barpublic 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;} }};
}
問題解答
回答1:第一個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'
這里有設置了padding,刪除這些即可
回答2:貼布局代碼上來,要學會問問題,這樣問誰也無法確切知道你的問題在哪,我只能估計你的布局xml保留了自動生成時的padding值,把這個去掉。
回答3:樓上正解,估計不是margin就是padding
相關文章:
1. html5 - iOS的webview加載出來的H5網頁,怎么修改html標簽select的樣式字體?2. java-se - 正在學習Java SE,為什么感覺學習Java就是在學習一些API。3. 一個mysql聯(lián)表查詢的問題4. 運行python程序時出現“應用程序發(fā)生異常”的內存錯誤?5. python - 如何使用pykafka consumer進行數據處理并保存?6. javascript - git clone 下來的項目 想在本地運行 npm run install 報錯7. 主從備份 - 跪求mysql 高可用主從方案8. python - django 里自定義的 login 方法,如何使用 login_required()9. mysql主從 - 請教下mysql 主動-被動模式的雙主配置 和 主從配置在應用上有什么區(qū)別?10. mysql - 一個表和多個表是多對多的關系,該怎么設計
