最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開(kāi)發(fā)實(shí)現(xiàn)ImageView寬度頂邊顯示,高度保持比例的方法

 更新時(shí)間:2018年02月02日 12:00:47   作者:zst1303939801  
這篇文章主要介紹了Android開(kāi)發(fā)實(shí)現(xiàn)ImageView寬度頂邊顯示,高度保持比例的方法,結(jié)合實(shí)例形式分析了Android ImageView界面布局及元素屬性動(dòng)態(tài)操作兩種功能實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android開(kāi)發(fā)實(shí)現(xiàn)ImageView寬度頂邊顯示,高度保持比例的方法。分享給大家供大家參考,具體如下:

ImageView 圖片寬度頂邊顯示,高度保持比例

1、在布局中設(shè)置

<ImageView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:paddingLeft="5dp"
  android:paddingRight="2.5dp"
  android:layout_weight="1"
  android:scaleType="fitXY"
  android:adjustViewBounds="true"
  android:src="@drawable/default_wallpaper_collection_cover"/>

主要是代碼:

android:scaleType="fitXY" :填充寬度match_parent
android:adjustViewBounds="true" :高度保持比例

2、代碼實(shí)現(xiàn)

public class MImageView extends ImageView {
  public MImageView(Context context) {
    super(context);
  }
  public MImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
  }
  public MImageView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
  }
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    Drawable drawable = getDrawable();
    if (drawable != null) {
      int width = MeasureSpec.getSize(widthMeasureSpec);
      int height = (int) Math.ceil((float) width * (float) drawable.getIntrinsicHeight() / (float) drawable.getIntrinsicWidth());
      setMeasuredDimension(width, height);
    } else {
      super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

新巴尔虎左旗| 从江县| 景泰县| 汝州市| 博湖县| 秀山| 汉阴县| 思茅市| 辰溪县| 长治市| 镇雄县| 汉川市| 盐池县| 阜宁县| 莒南县| 玉林市| 苍梧县| 鄯善县| 阿城市| 古丈县| 南康市| 永兴县| 揭西县| 永德县| 左贡县| 鹰潭市| 邯郸县| 特克斯县| 双峰县| 平乐县| 鲁山县| 新巴尔虎左旗| 洛川县| 新建县| 克什克腾旗| 武强县| 类乌齐县| 莫力| 璧山县| 福清市| 栾川县|