我的布局有一些问题,这是我的布局充气器的捕获
布局太大,按钮位置错误,我没有使用标题,但其中有黑色标题背景
我只是想让它像钢琴瓷砖布局一样小
谁能帮我解决这个问题吗?
这是我的layout.xml
数据,它将在menu.java
中显示充气器布局
<?xml version='1.0' encoding='utf-8'?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="@drawable/backgroundblankwhite"
android:gravity="center|center_horizontal|center_vertical"
android:orientation="vertical"
android:padding="10sp" >
<TextView
android:id="@+id/exitimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/textinflateexit"
android:singleLine="true" >
<requestFocus />
</TextView>
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="@+id/buttonexityes"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:background="@drawable/buttonquityes" />
<Button
android:id="@+id/buttonexitno"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:background="@drawable/buttonquitno" />
</LinearLayout>
</LinearLayout>
这是我的 menu.java
,它有一个按钮来显示我的膨胀布局
public class menu extends Activity {
private Context context = this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.menu);
Button exit = (Button) findViewById(R.id.exit);
exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
final Dialog openDialog = new Dialog(context);
openDialog.setContentView(R.layout.inflatequitapp);
TextView dialogTextContent = (TextView)openDialog.findViewById(R.id.exitimage);
Button dialogExitButton = (Button)openDialog.findViewById(R.id.buttonexityes);
dialogExitButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// if this button is clicked, close
// current activity
menu.this.finish();
}
});
Button dialogCloseButton = (Button)openDialog.findViewById(R.id.buttonexitno);
dialogCloseButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
openDialog.dismiss();
}
});
openDialog.show();
}
});
}
@Override
public void onBackPressed() {
// do nothing.
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
}
最佳答案
我已经更改了一个位变量以在我的末尾进行检查..请更改变量,类以在您的末尾进行匹配...
MainActivity.java
///---////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
Button exit = (Button) findViewById(R.id.but);
exit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
final Dialog openDialog = new Dialog(MainActivity.this);
openDialog.setContentView(R.layout.main);
openDialog.setTitle("Confirm Exit");
TextView dialogTextContent = (TextView)openDialog.findViewById(R.id.exitimage);
Button dialogExitButton = (Button)openDialog.findViewById(R.id.buttonexityes);
dialogExitButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
finish();
}
});
Button dialogCloseButton = (Button)openDialog.findViewById(R.id.buttonexitno);
dialogCloseButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
openDialog.dismiss();
}
});
openDialog.show();
}
});
}
对话框 xml 文件..
<?xml version='1.0' encoding='utf-8'?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#ffffff"
android:gravity="center|center_horizontal|center_vertical"
android:orientation="vertical"
android:padding="10sp" >
<TextView
android:id="@+id/exitimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:singleLine="true"
android:text="Are You Sure!!" >
<requestFocus />
</TextView>
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="@+id/buttonexityes"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:background="#ffffff"
android:text="Yes" />
<Button
android:id="@+id/buttonexitno"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:background="#ffffff"
android:text="No" />
</LinearLayout>
</LinearLayout>
输出:
关于java - 将 Inflate 布局设置为更小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32175189/