• Android--样式经验


    <style name="AppTheme" parent="android:Theme.Light">
            <item name="android:textColorPrimaryInverse">@android:color/primary_text_light</item>
            <item name="android:windowFullscreen">true</item>
            <item name="android:windowNoTitle">true</item>
        </style>

    textColorPrimaryInverse 意思就是颜色反转

    windowFullscreen         全屏 

    windowNoTitle            无标题

    比如一般的Theme,是黑色背景的话文字的首要颜色就是看上去是白色的颜色,也就是textColorPrimary(黑变白)

    而我们有时候会通过代码或者 XML设置这个Theme的inverse的背景,就是说变成白色的背景的话文字的首要颜色就是看上去是黑色的颜色,也就是 textColorPrimaryInverse(白变黑)

     android:gravity="center_horizontal|bottom"

    对于容器内的空间水平居中&&底部对齐(双属性中间用|分开)

    layout_weight体验(实现按比例显示)

    注:LinearLayout中的TextView按比例显示的时候,layout_width="0dp"或者layout_height="0dp"

    在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场 景显得非常重要,比如我们需要按比例显示。android并没用提供table这样的控件,虽然有TableLayout,但是它并非是我们想象中的像 html里面的table那么好用,我们常用ListView实现table的效果,但是列对齐确比较麻烦,现在用LinearLayout及属性 android:layout_weight能很好地解决。下面我们共同体验下layout_weight这个属性。

      一、LinearLayout内的控件的layout_width设置为"wrap_content",请看一下xml配置:

     <LinearLayout
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_weight="1">
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_weight="1"
              android:background="#aa0000"
              android:gravity="center"
              android:text="1"/>
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_weight="2"
              android:background="#00aa00"
              android:gravity="center"
              android:text="1"/>
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_weight="3"
              android:background="#0000aa"
              android:gravity="center"
              android:text="1"/>
      </LinearLayout>

    效果如下:

    可以看到这三个TextView是按照1:2:3的比例进行显示的,这样看来似乎可以实现按照比例显示了,但是有个问题,如果TextView内的文本长度一同那么较长文本的TextView会宽度会有所增加,见下面配置及效果:

    配置:

     <LinearLayout
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_weight="1">
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_weight="1"
              android:background="#aa0000"
              android:gravity="center"
              android:text="1111111111111111111111111111111111111111111"/>
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_weight="2"
              android:background="#00aa00"
              android:gravity="center"
              android:text="2"/>
          <TextView
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:layout_weight="3"
              android:background="#0000aa"
              android:gravity="center"
              android:text="3"/>
      </LinearLayout>

    效果:

    这样看来我们所需要的按比例又无法实现了,经过满天地google终于找到了解决方案,就是设置layout_width设置为"wrap_content"。配置及效果见下:

     <LinearLayout
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:layout_weight="1">
          <TextView
              android:layout_width="0dp"
              android:layout_height="fill_parent"
              android:layout_weight="1"
              android:background="#aa0000"
              android:gravity="center"
              android:text="1111111111111111111111111111111111111111111"/>
          <TextView
              android:layout_width="0dp"
              android:layout_height="fill_parent"
              android:layout_weight="2"
              android:background="#00aa00"
              android:gravity="center"
              android:text="2"/>
          <TextView
              android:layout_width="0dp"
              android:layout_height="fill_parent"
              android:layout_weight="3"
              android:background="#0000aa"
              android:gravity="center"
              android:text="3"/>
      </LinearLayout>

    效果:

    这样终于达到我们的按比例显示的效果了

  • 相关阅读:
    MySQL Limit优化(转)
    MySQL数据库性能优化思路与解决方法(一转)
    Mysql占用CPU过高如何优化?(转)
    数据库方面两个简单实用的优化方法(转)
    硬盘扩容9999T
    python内涵段子爬取练习
    jmeter环境配置
    PyCharm3.0默认快捷键
    python3 操作页面上各种元素的方法
    python3 selenium webdriver 元素定位xpath定位骚操作
  • 原文地址:https://www.cnblogs.com/WTFly/p/3555695.html
Copyright © 2020-2023  润新知