Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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
Android 如何更改开关小部件的高度?_Android_Xml_Widget - Fatal编程技术网

Android 如何更改开关小部件的高度?

Android 如何更改开关小部件的高度?,android,xml,widget,Android,Xml,Widget,我想让我的开关小部件更大,所以我必须改变开关的高度 但我没有办法解决这个问题 我看了这个问题: 我做了一张这样的画: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:width="0dp" android:height="30dp">

我想让我的开关小部件更大,所以我必须改变开关的高度

但我没有办法解决这个问题

我看了这个问题:

我做了一张这样的画:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"  android:width="0dp" android:height="30dp">
    <solid android:color="#FF4444"  />
</shape>
<Switch
android:id="@+id/sw_trackLiveData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_liveData"
android:layout_alignRight="@+id/btn_stoptrip1"
android:layout_alignLeft="@+id/btn_stoptrip1"
android:layout_marginTop="10dp"
android:thumbTextPadding="25dp"
android:switchMinWidth="56dp" 
android:track="@drawable/roundedbutton"
android:layout_centerHorizontal="true"
android:textSize="20dp" />

然后我像这样设置开关:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"  android:width="0dp" android:height="30dp">
    <solid android:color="#FF4444"  />
</shape>
<Switch
android:id="@+id/sw_trackLiveData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_liveData"
android:layout_alignRight="@+id/btn_stoptrip1"
android:layout_alignLeft="@+id/btn_stoptrip1"
android:layout_marginTop="10dp"
android:thumbTextPadding="25dp"
android:switchMinWidth="56dp" 
android:track="@drawable/roundedbutton"
android:layout_centerHorizontal="true"
android:textSize="20dp" />

但它不起作用。我做错了什么事。有谁能给我举个例子说明如何做对吗?或者有人能帮我解决这个问题吗?

只要改变就行了

android:layout_width="wrap_content"
android:layout_height="wrap_content"

换衣服

android:layout_width="wrap_content"
android:layout_height="wrap_content"


更改roundedButton.xml,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <size
        android:height="20dp"
        android:width="56dp" />
    <solid android:color="#FF4444" />

</shape>

更改roundedButton.xml,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <size
        android:height="20dp"
        android:width="56dp" />
    <solid android:color="#FF4444" />

</shape>

在drawable(custom_Selector.xml)中将开关选择器更改为下方


并在drawable(custom_Track.xml)中创建曲目


并在Xml文件中:

<Switch
  android:id="@+id/switch"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_marginRight="16dp"
  android:textOff="OFF"
  android:scaleX="2"
  android:scaleY="2"
  android:textOn="ON"
  android:thumb="@drawable/customswitchselector"
  android:track="@drawable/custom_track" />

在drawable(custom_Selector.xml)中将开关选择器更改为下方


并在drawable(custom_Track.xml)中创建曲目


并在Xml文件中:

<Switch
  android:id="@+id/switch"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_marginRight="16dp"
  android:textOff="OFF"
  android:scaleX="2"
  android:scaleY="2"
  android:textOn="ON"
  android:thumb="@drawable/customswitchselector"
  android:track="@drawable/custom_track" />


我刚刚浏览了您的示例,我能够重现您的情况。正如dato在他的帖子中所说,解决方案是必须使用元素。您在元素中使用的android:height=“…”和android:width=“…”属性无效,因为我刚刚浏览了您的示例,并且能够重新创建您的情况。正如dato在他的帖子中所说,解决方案是必须使用元素。元素中使用的android:height=“…”和android:width=“…”属性无效,因为我认为设置android:layout_width只会影响开关前面文本标签的宽度,而不会影响实际滑动开关的宽度。同样,设置layout_高度会调整整个小部件的高度,但不会改变滑动开关的高度。问题是指整个小部件,包括开关图形,而不仅仅是外部容器。我认为设置android:layout_宽度只会影响开关前面文本标签的宽度,不是实际滑动开关的宽度。同样,设置layout_height会调整整个小部件的高度,但不会改变滑动开关的高度。问题是指整个小部件,包括开关图形,而不仅仅是外部容器。