Android 使用XML设置弹出窗口格式
为了控制这个弹出窗口,我花了很长时间,请参见下面的图1 正如您在上面的屏幕抓取中所看到的,弹出窗口延伸到屏幕边距之外,并带有一些按钮。XML和代码是五年前编写的,从那时起,使用这个XML和Android Studio构建它,它将以适当的屏幕边距很好地显示出来。见下图2 以下是与布局相关的弹出窗口编程部分Android 使用XML设置弹出窗口格式,android,android-studio,android-xml,Android,Android Studio,Android Xml,为了控制这个弹出窗口,我花了很长时间,请参见下面的图1 正如您在上面的屏幕抓取中所看到的,弹出窗口延伸到屏幕边距之外,并带有一些按钮。XML和代码是五年前编写的,从那时起,使用这个XML和Android Studio构建它,它将以适当的屏幕边距很好地显示出来。见下图2 以下是与布局相关的弹出窗口编程部分 public class speciesPopupWindow { public static Context ctx; Button btnDismiss, btnSaveRecord, b
public class speciesPopupWindow {
public static Context ctx;
Button btnDismiss, btnSaveRecord, btnPurgeTable, btnUpdateRecord, btnDeleteRecord, btnClearForm, btnFirstRecord, btnPreviousRecord, btnNextRecord, btnLastRecord;
SQLiteDatabase db;
EditText edSpeciesLookup, edSpeciesLookupRowid;
DBAdapter msdb;
public speciesPopupWindow(Context ctx) {
speciesPopupWindow.ctx = ctx;
}
public void init() {
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View popUpView = inflater.inflate(R.layout.species_popup_layout, null, false);
final PopupWindow popup = new PopupWindow(popUpView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
popUpView.setBackgroundColor(Color.rgb(255, 204, 153));
popup.showAtLocation(popUpView, Gravity.CENTER_VERTICAL, 0, 0);
popup.setContentView(popUpView);
edSpeciesLookup = (EditText) popUpView.findViewById(R.id.editSpeciesLookupsxml);
edSpeciesLookupRowid = (EditText) popUpView.findViewById(R.id.editSpeciesLookupRowidxml);
btnDismiss = (Button) popUpView.findViewById(R.id.btndismissxml);
btnDismiss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popup.dismiss();
}
});
btnSaveRecord = (Button) popUpView.findViewById(R.id.btnSaveRecordxml);
btnSaveRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveRecord();
}
});
...
}
}
这是XML
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#000000"
android:background="@drawable/customborder">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_height="wrap_content"
android:layout_marginLeft="18dip"
android:text="Rowid:" />
<EditText
android:id="@+id/editSpeciesLookupRowidxml"
android:editable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="1"
android:enabled="false"
android:selectable="false"
android:persistent="false"
android:textColor="#000000"
android:layout_marginRight="10dip"
android:text=""/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dip"
android:textColor="#000000"
android:text="Species:"
android:textStyle="italic" />
<EditText
android:id="@+id/editSpeciesLookupsxml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_span="3"
android:layout_marginRight="10dip"
android:inputType="textNoSuggestions"/>
</TableRow>
<TableRow>
<Button
android:id="@+id/btnSaveRecordxml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:text="SAVE"
android:textSize="14dp" />
<Button
android:id="@+id/btnUpdateRecordxml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="UPDATE"
android:textSize="14dp" />
<Button
android:id="@+id/btnDeleteRecordxml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DELETE"
android:textSize="14dp" />
<Button
android:id="@+id/btnClearFormxml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CLEAR"
android:textSize="14dp"
android:layout_marginRight="10dip"/>
</TableRow>
<TableRow>
<Button
android:id="@+id/btnFirstRecordxml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:text="@string/pszFirstRecordButton"/>
<Button
android:id="@+id/btnPreviousRecordxml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pszPreviousRecordButton"/>
<Button
android:id="@+id/btnNextRecordxml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pszNextRecordButton"/>
<Button
android:id="@+id/btnLastRecordxml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:text="@string/pszLastRecordButton"/>
</TableRow>
<TableRow>
<Button
android:id="@+id/btnPurgeTablexml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="Purge Table!"
android:textSize="14dp"
android:layout_marginLeft="10dip"
android:layout_marginBottom="10dip"/>
<Button
android:id="@+id/btndismissxml"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="Dismiss"
android:layout_marginRight="10dip"
android:layout_marginBottom="10dip"
android:textSize="14dp" />
</TableRow>
问题:我觉得java类中的布局代码与XML冲突……如何调整speciesPopupWindow,使所有布局都来自XML?具体来说,我需要调整弹出窗口,使其出现在屏幕范围内。我尝试了许多XML和对java编程的调整,但没有取得显著的成功。提前谢谢