我正在尝试为具有给定文本大小的一些文本视图设计。更改样式的大小对文本视图无济于事,而在布局XML中更改它的效果正确。我想念什么?
样式:
<style name="SliderTextTheme">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">25sp</item>
<item name="android:textAlignment">center</item>
</style>
textView的布局xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_dark"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
android:id="@+id/image_frame"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="top"
android:layout_weight="5">
<ImageView
android:id="@+id/color_wheel"
android:src="@drawable/color_wheel_730"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
<LinearLayout
android:id="@+id/slider_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_red"
android:text="@string/color_red"/>
<SeekBar
style="@style/ColorSeekBar"
android:id="@+id/red_seekbar"
android:progressTint="@color/RGBW_red"
android:thumbTint="@color/RGBW_red" />
<TextView
android:id="@+id/red_value"
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_red"
tools:text="100" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_green"
android:text="@string/color_green"/>
<SeekBar
style="@style/ColorSeekBar"
android:progressTint="@color/RGBW_green"
android:thumbTint="@color/RGBW_green" />
<TextView
android:id="@+id/green_value"
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_green"
tools:text="100" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_blue"
android:text="@string/color_blue"/>
<SeekBar
style="@style/ColorSeekBar"
android:progressTint="@color/RGBW_blue"
android:thumbTint="@color/RGBW_blue" />
<TextView
android:id="@+id/blue_value"
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_blue"
tools:text="100" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_white"
android:text="@string/color_white"/>
<SeekBar
style="@style/ColorSeekBar"
android:progressTint="@color/RGBW_white"
android:thumbTint="@color/RGBW_white" />
<TextView
android:id="@+id/white_value"
style="@style/SliderTextTheme"
android:textColor="@color/RGBW_white"
tools:text="100" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/button_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="bottom">
<Button
android:id="@+id/test_button_1"
android:layout_alignParentLeft="true"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:padding="10dp"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:text="Send Colors"/>
</RelativeLayout>
</LinearLayout>
预先感谢您。汤姆
我能够通过更改
来使您的样式工作并调整文本大小<item name="android:layout_width">0dp</item>
to
<item name="android:layout_width">wrap_content</item>
如果您需要0dp宽度来处理自己的重量属性,请检查以确保您正在操纵的文本视图绝对位于线性层次内。
确保将parent = textview widtget用于您的样式并使用了Android:TextSize,而不仅仅是您的样式内的textsize属性。