Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
XML-Android复选框小部件_Android_Xml - Fatal编程技术网

XML-Android复选框小部件

XML-Android复选框小部件,android,xml,Android,Xml,非常感谢。我是android的开始。我正在尝试一个复选框按钮。我做了一个小项目。请参见我的项目照片: 1.为什么复选框列表的位置不一样,就像一个随机列表 检查我的Xml代码: 2.我使用的是安卓:layout_marginTop=“30dp”,安卓:textSize=“20dp”,这是完美的申报规则吗?它将支持所有设备吗 <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_cont

非常感谢。我是android的开始。我正在尝试一个复选框按钮。我做了一个小项目。请参见我的项目照片:

1.为什么复选框列表的位置不一样,就像一个随机列表

检查我的Xml代码:

2.我使用的是安卓:layout_marginTop=“30dp”,安卓:textSize=“20dp”,这是完美的申报规则吗?它将支持所有设备吗

<CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Wonton Soup " 
        android:layout_marginTop="30dp"
        android:layout_gravity="center"
        android:textSize="20dp"
        />

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Egg Drop Soup " 
         android:layout_gravity="center"
         android:layout_marginTop="10dp"
         android:textSize="20dp"
        />
    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="French Fries " 
         android:layout_gravity="center"
         android:textSize="20dp"
         android:layout_marginTop="10dp"
        />


再次非常感谢

1.为什么复选框列表的位置不一样,就像一个随机列表

您正在使用android:layout\u gravity=“center”将复选框居中。请注意,每个复选框的边界都位于其父复选框的中心

也许你所期待的是以下几点:

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center">

    <CheckBox ... />

    <CheckBox ... />

    <CheckBox ... />

</LinearLayout>

然后,复选框将在一个中心框内左对齐,该框包裹其宽度

2.我使用的是安卓:layout_marginTop=“30dp”,安卓:textSize=“20dp”,这是完美的申报规则吗?它将支持所有设备吗

我不知道你问这个问题是什么意思,但有两个可能的问题:

  • 如果布局没有滚动,则布局可能会在屏幕较小的设备上超出其边界。一个简单的解决方案可能是将整个布局包装在ScrollView中

  • 不建议对文本使用DPs,因为用户可能已经设置了文本缩放的首选项:
    android:textSize=“20sp”

    或者,您可能希望使用Android的预设文本外观之一,例如:
    Android:textAppearance=“?Android:attr/textAppearanceLarge”


  • 第一步。将所有复选框放入线性布局

    第二步。设置所有复选框属性

              android:layout_gravity = "left"
    

    因为您的文本长度对于所有复选框都不相同。将值放入文本视图的“最大长度”字段中。像

      <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >
    
    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
    
        android:maxWidth="125dp"
        android:text="French Fries /Testsatrs"
        android:textSize="20dp" />
    
    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
    
        android:text="French Fries "
        android:textSize="20dp" 
        android:maxWidth="125dp"/>
    
    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="French Fries " 
        android:maxWidth="125dp"
         android:textSize="20dp"
         android:layout_marginTop="10dp"
    
        />
    
       </LinearLayout>
    
    
    
    android:textSize=“20dp”
    对于文本视图,您应该使用sp而不是dp。您可以告诉我您将所有复选框都放在哪个布局中吗?非常感谢@Paul Lammertsma!!我可以声明直接android:layout\u marginTop=“30dp”吗?此30dp大小将与所有设备的大小相同??如果不是直接声明,那么我做什么完美的使用??,所以大小将是相同的物理大小在每个设备上。如果您希望在大型设备(如平板电脑)上拥有更大的利润空间,那么我建议您使用资源限定符定义不同的维度;为此。