CONMISANMA的正确答案——Android详解ImageButton属性

转载自1:Android--(6)--详解ImageButton属性

转载自2:Android 图像按钮ImageButton


测试系统:DEEPIN LINUX 15.6

测试软件:ANDROID STUDIO 3.1.3

测试机器:i6200扫描枪


ImageButton是android.widget.ImageView的子类

android:src                                  : 这将设置一个可绘制的 ImageView 内容 
android:adjustViewBounds       :设置为true,如果想调整ImageView其边界,以保持其绘制的高宽比 
android:baseline                         : 这是偏移此视图内部基线 
android:baselineAlignBottom   : 如果为true,则图像视图会基于其底部边缘基线对齐 
android:cropToPadding             : 如果为true,图像将被裁剪以适合其填充之内 
android:background                   :这是一个可拉伸使用来做背景 
android:contentDescription      :定义文本简要描述视图内容 
android:onClick                          :在本视图的上下文视图被点击时调用的方法的名称 
android:visibility                         : 控制视图的初始可视性 


XML使用:

       <ImageButton
            android:id="@+id/img1"
            android:src="@drawable/logo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:layout_marginBottom="30dp"
             />


Activity(JAVA)使用:

private ImageButton ib_image;
ib_image = findViewById(R.id.img1);
ib_image.setOnTouchListener(new View.OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    return false;
  }
});



猜你喜欢

转载自blog.csdn.net/fengwangzhe000/article/details/80987245