如何修改此主题以防止Button文本与TextView文本重叠?

时间:2013-08-22 09:10:24

标签: android android-theme android-styles

我有一个布局,当没有应用样式时显示如下(硬编码样式除外,例如适用于两个实例的颜色和字体):

enter image description here

但是当我应用样式时它看起来像这样:

enter image description here

布局定义为:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout1"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">
    <TextView
        android:id="@+id/txtBlock"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="[Block Name]"
        android:textSize="15sp"
        android:layout_gravity="center" />
    <Button
        android:gravity="left|bottom"
        android:background="@null"
        android:text="[Block Status]"
        android:id="@+id/btnStatus"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/imgAlarm"
        android:layout_alignParentLeft="true" />
    <ImageButton
        android:id="@id/imgAlarm"
        android:background="@null"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/alarm"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true" />
</RelativeLayout>

我的styles.xml定义为:

<resources>

  <!-- Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices. -->
  <style name="AppBaseTheme" parent="android:Theme.Light">
    <!-- Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here. -->
  </style>

  <!-- Application theme. -->
  <style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
  </style>

  <style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowBackground">@null</item>
  </style>

  <style name="ButtonBar">
    <item name="android:paddingLeft">2dp</item>
    <item name="android:paddingTop">5dp</item>
    <item name="android:paddingRight">2dp</item>
    <item name="android:paddingBottom">0dp</item> 
    <item name="android:background">@android:drawable/bottom_bar</item>
  </style>

  <style name="ButtonBarButton" />

  <style name="keypad_button" >
    <item name="android:layout_width" >fill_parent</item>
    <item name="android:layout_height" >wrap_content</item>
    <item name="android:textColor" >#ffffff</item>
    <item name="android:gravity" >center</item>
    <item name="android:textSize" >15sp</item>
    <item name="android:width">65dp</item>
  </style>

  <!--<style name="CustomTheme" parent="@android:style/Theme">
    <item name="android:tabWidgetStyle">@style/CustomTabWidget</item>
  </style>
  <style name="CustomTabWidget" parent="@android:style/Widget.TabWidget">
    <item name="android:textAppearance">@style/CustomTabWidgetText</item>
  </style>
  <style name="CustomTabWidgetText" parent="@android:style/TextAppearance.Widget.TabWidget">
    <item name="android:textSize">50sp</item>
    <item name="android:textStyle">bold</item>
  </style>-->

</resources>

我需要做些什么才能防止文字重叠?

2 个答案:

答案 0 :(得分:1)

尝试线性布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout1"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal">
    <LinearLayout
        android:id="@+id/layout2"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <TextView
            android:id="@+id/txtBlock"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="[Block Name]"
            android:textSize="15sp"
            android:layout_gravity="center" />
        <Button
            android:gravity="left|bottom"
            android:background="@null"
            android:text="[Block Status]"
            android:id="@+id/btnStatus"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/imgAlarm"
            android:layout_alignParentLeft="true" />
    </LinearLayout>
    <ImageButton
        android:id="@id/imgAlarm"
        android:background="@null"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/alarm"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true" />
</LinearLayout>

答案 1 :(得分:1)

像这样更改你的xaml:

<Button
        android:gravity="left|bottom"
        android:background="@null"
        android:text="[Block Status]"
        android:id="@+id/btnStatus"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/txtBlock"
        android:layout_toLeftOf="@+id/imgAlarm"
        android:layout_alignParentLeft="true" />

刚刚将android:layout_below =“@ id / textBlock”添加到你的xml

相关问题