У меня есть пользовательский набор для большого пальца для Switch
виджета внутри LinearLayout
. Я не могу заставить его правильно отображаться на всех видах экранов. На большинстве экранов это выглядит так:
Это нормально, но на некоторых экранах (например, 440 dpi) это выглядит так this-
Как сделать так, чтобы это выглядело одинаково на всех экранах? Я пробовал много вещей, в том числе switchMinWidth
, установив android:width=
в 0dp, используя thumbTextPadding
, но ничего не работает. Все имеет точный тот же результат, он работает на некоторых экранах, но не на других.
Вот мой Switch
виджет, помещенный в LinearLayout
с layout_weight
из 2. Там обычно 5 виджетов в каждом горизонтальном LinearLayout
, но этот спецификатор c один имеет 4, так как Switch
должен занимать 2 слота.
<Switch
android:id="@+id/btndegreerad"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@drawable/degree_rad_track"
android:showText="true"
android:switchTextAppearance="@style/SwitchTextTheme"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textOff="@string/btnrad"
android:textOn="@string/btndegree"
android:thumb="@drawable/degree_rad_thumb"
android:thumbTextPadding="@dimen/_3sdp"
android:thumbTint="@color/colorSwitch"
android:track="@drawable/degree_rad_track" />
Вот degree_rad_thumb
drawable-
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false">
<shape android:shape="rectangle">
<size android:height="@dimen/_38sdp" android:width="0dp"/>
<corners android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topRightRadius="10dp"
android:topLeftRadius="10dp"/>
</shape>
</item>
<item android:state_checked="true">
<shape android:shape="rectangle">
<size android:height="@dimen/_38sdp" android:width="0dp"/>
<corners android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topRightRadius="10dp"
android:topLeftRadius="10dp"/>
</shape>
</item>
</selector>
Вот также degree_rad_track
, хотя это, вероятно, не требуется-
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false">
<shape android:shape="rectangle">
<solid android:color="@color/colorFadedPrimary"/>
<corners android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topRightRadius="10dp"
android:topLeftRadius="10dp"/>
</shape>
</item>
<item android:state_checked="true">
<shape android:shape="rectangle">
<solid android:color="@color/colorFadedPrimary"/>
<corners android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topRightRadius="10dp"
android:topLeftRadius="10dp"/>
</shape>
</item>
</selector>