java - 将 Inflate 布局设置为更小

标签 java android xml android-layout layout

我的布局有一些问题,这是我的布局充气器的捕获

enter image description here

布局太大,按钮位置错误,我没有使用标题,但其中有黑色标题背景

我只是想让它像钢琴瓷砖布局一样小

enter image description here

谁能帮我解决这个问题吗?

这是我的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>

输出:

enter image description here

关于java - 将 Inflate 布局设置为更小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32175189/

相关文章:

Java - 何时使用 'this' 关键字

java - 如何以编程方式 'set' 对话框的所有参数,例如 'dialog title' 、 'ok text' 等,而无需将字符串文字作为参数?

Android VPNService - 如何从我的 Activity 中调出 'system-managed dialog'?

R 中带有嵌套兄弟数据框的 xml

java - jframe 不适合窗口

java - ScheduledThreadPoolExecutor scheduleWithFixedDelay 和 "urgent"执行

java - 单击一次广告即可打开数百个标签

android - 在 recyclerview 中向下滚动,微调器中的选定项目发生变化

python - 使用 dicttoxml 模块从字典生成时,xml 字符串包含在 b'<xml_string>' 中

java - 删除 jaxb 编码中的空 XML 标记