<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      安卓筆記俠

      專注安卓開發

      導航

      按照指定比例展示寬高的自定義控件實現

      1.json

      2.按照指定比例展示寬高的自定義控件實現

      為了讓圖片按照完美比例進行展現, 不被壓縮, 需要自定義控件,該控件可以根據預設的比例來確定寬高

       * 按照比例展示寬高的自定義控件
       * 
       * @author Kevin
       * 
       */
      public class RatioLayout extends FrameLayout {
      
          private float ratio;
      
          public RatioLayout(Context context, AttributeSet attrs, int defStyle) {
              super(context, attrs, defStyle);
          }
      
          public RatioLayout(Context context, AttributeSet attrs) {
              super(context, attrs);
              // 加載自定義屬性的值
              TypedArray typedArray = context.obtainStyledAttributes(attrs,
                      R.styleable.RatioLayout);
              // 根據屬性id獲取屬性值, 方式: R.styleable.名稱_屬性
              ratio = typedArray.getFloat(R.styleable.RatioLayout_ratio, 0);
              // 回收TypedArray, 釋放內存
              typedArray.recycle();
          }
      
          public RatioLayout(Context context) {
              super(context);
          }
      
          @Override
          protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
              int widthMode = MeasureSpec.getMode(widthMeasureSpec);
              int heightMode = MeasureSpec.getMode(heightMeasureSpec);
      
              int widthSize = MeasureSpec.getSize(widthMeasureSpec);
              int heightSize = MeasureSpec.getSize(heightMeasureSpec);
      
              // MeasureSpec.EXACTLY 確定值, 比如把寬高值寫死,或者match_parent
              // MeasureSpec.AT_MOST 至多, 能撐多大就多大, 類似wrap_content
              // MeasureSpec.UNSPECIFIED 未指定大小
      
              if (widthMode == MeasureSpec.EXACTLY
                      && heightMode != MeasureSpec.EXACTLY && ratio != 0) {
                  // 1. 根據布局寬度推算圖片寬度
                  int imageWidth = widthSize - getPaddingLeft() - getPaddingRight();
                  // 2. 根據圖片寬度和寬高比,推算圖片高度
                  int imageHeight = (int) (imageWidth / ratio);
                  // 3. 根據圖片高度, 推算布局高度
                  heightSize = imageHeight + getPaddingTop() + getPaddingBottom();
                  // 4. 根據布局高度, 推算heightMeasureSpec
                  heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize,
                          MeasureSpec.EXACTLY);
              }
      
              super.onMeasure(widthMeasureSpec, heightMeasureSpec);
          }
      
      }
      

      自定義屬性

      values/attrs.xml
      
      <?xml version="1.0" encoding="utf-8"?>
      <resources>
      
          <declare-styleable name="RatioLayout">
              <attr name="ratio" format="float" />
          </declare-styleable>
      
      </resources>
      

        

        

      xml

      <?xml version="1.0" encoding="utf-8"?>
      
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:itheima="http://schemas.android.com/apk/res/com.itheima.googleplay74"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical" >
      ?
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
              android:layout_marginRight="5dp"
              android:background="@drawable/list_item_bg_selector"
              android:orientation="vertical" >
      ?
              <com.itheima.googleplay74.ui.view.RatioLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  itheima:ratio="2.43" >
                  <ImageView
                      android:id="@+id/iv_pic"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:src="@drawable/subject_default" />
              </com.itheima.googleplay74.ui.view.RatioLayout>
      ?
              <TextView
                  android:id="@+id/tv_title"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:padding="5dp"
                  android:text="標題"
                  android:textColor="#000"
                  android:textSize="18sp" />
          </LinearLayout>
      </LinearLayout>
      

        

       

      posted on 2016-11-27 18:11  安卓筆記俠  閱讀(770)  評論(1)    收藏  舉報

      主站蜘蛛池模板: 久久这里只精品国产免费9| 中文字幕无码视频手机免费看| 丝袜美腿亚洲综合在线观看视频| 无码日韩做暖暖大全免费不卡| 精品国产一区二区三区av性色| 亚洲av专区一区| 神马久久亚洲一区 二区| 伊人久久大香线蕉av色婷婷色| 久久av色欲av久久蜜桃网| 国产成人高清精品亚洲一区| 伊人久久大香线蕉网av| 中国女人内谢69xxxx| 国外av片免费看一区二区三区| 特级毛片在线大全免费播放| 福安市| 国产91色综合久久免费| 少妇熟女久久综合网色欲| 国产乱国产乱老熟300部视频| 精品精品亚洲高清a毛片| 日韩卡一卡2卡3卡4卡| 亚洲欧美日韩国产四季一区二区三区| 台前县| 精品国产乱码久久久久久浪潮| 欧美成本人视频免费播放| 乱码精品一区二区三区| 性男女做视频观看网站| 激情综合网激情五月俺也去| 樱花草视频www日本韩国 | 欧美激情精品久久| 欧美丰满熟妇性xxxx| 日韩精品一区二区三免费| 强d乱码中文字幕熟女1000部| 欧美福利电影A在线播放| 国产精品久久久久久亚洲色| 久久人人爽人人爽人人av| 视频二区中文字幕在线| 色秀网在线观看视频免费| 国产高清在线男人的天堂| 两个人看的www免费视频中文| 亚洲欧洲日产国码久在线| 日韩人妻一区中文字幕|