一:LinearLayout+RelativeLayout图表效果


       

            1:每个柱子外面是RelativeLayout里边LinearLayout,使用android:layout_alignParentBottom="true"在父容器底部对齐

                  用背景颜色控制即可

            2:中间文字水平垂直居中:

                   父容器控制水平居中android:layout_alignParentBottom="true"

                   自己垂直居中 android:layout_gravity="center_vertical"   

                                         

             3:三个柱子左右两边间距保持一样

                  只需要在外层水平居中就可以了,外层的宽度等于内容宽度    android:layout_width="wrap_content"

           


            所有布局文件1版

<?xml version="1.0" encoding="utf-8"?>                                                                                                                                                           

    2版

        

<?xml version="1.0" encoding="utf-8"?>                                                                                                                                                                                                                                                                                                                                                                        
    

         后台效果

public class TestChat extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.testchat);        SetOil(100,70); }     private void SetOil(double maxoval, double currentovl)//maxoval最高刻度,当前油量currentovl { TextView tv = (TextView)findViewById(R.id.firshOilBoxText); tv.setText(currentovl+"T"); LinearLayout ly = (LinearLayout)findViewById(R.id.firshOilBox); RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams)ly.getLayoutParams();  RelativeLayout lyf = (RelativeLayout)findViewById(R.id.firshOilF); LinearLayout.LayoutParams lpf = (LinearLayout.LayoutParams)lyf.getLayoutParams();  double precendvalue = (currentovl/maxoval);//先计算所占高度的百度分 System.out.println("百分比:"+precendvalue); int needheight = (int)(precendvalue*lpf.height);//在取得该百分比在当前高度下占有的高度,获取到的单位已经是dp不用再转化了  lp.height = needheight; ly.setLayoutParams(lp); }   public int Dp2Px(Context context, float dp) {     final float scale = context.getResources().getDisplayMetrics().density;     return (int) (dp * scale + 0.5f);      }}








更多相关文章

  1. android 使用Activity类布局时怎样让图片居中
  2. Android开发学习:ImageView的scaletype属性
  3. 按键及其居中
  4. Android开发学习:ImageView的scaletype属性
  5. android 横竖屏等设置
  6. Android(安卓)TextView 45°倾斜效果
  7. Android(安卓)TextView文字旋转45°
  8. Android(安卓)、BlackBerry 文本对齐方式对比
  9. Android(安卓)TextView的滑动

随机推荐

  1. 浅析Android手机卫士手机定位的原理
  2. Android音频开发(4):PCM转WAV格式音频
  3. Android(安卓)App更改背景颜色
  4. 【Android】Android(安卓)4.0 无法接收开
  5. 分享10个Android游戏源码,要的赶紧来哈
  6. Android(安卓)Trick 8: ProgressBar的圆
  7. android 布局
  8. android 设置 TextView
  9. Android音频开发(4):PCM转WAV格式音频
  10. Android(安卓)RelativeLayout属性