安卓课程二十二 ImageView的基本用法
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/scaletype_center" /> <ImageView android:id="@+id/im1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/duo2" android:scaleType="center" android:background="#f00" android:contentDescription="@string/scaletype_center" /> <TextView android:id="@+id/tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/scaletype_fitCenter" android:layout_marginTop="20dp" android:background="#f00" /> <ImageView android:id="@+id/im2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/duo2" android:scaleType="fitCenter" android:background="#900" android:contentDescription="@string/scaletype_fitCenter" /> </LinearLayout>
MainActivity.java
import android.app.Activity; import android.os.Bundle; import android.widget.ImageView; import android.widget.LinearLayout; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView imv1 = (ImageView) this.findViewById(R.id.im1); ImageView imv2 = (ImageView) this.findViewById(R.id.im2); /** * 设置imv1图片宽高,不能适用大小 */ imv1.setLayoutParams(new LinearLayout.LayoutParams(50,50)); /** * 设置imv1图片宽高,自动调整大小 */ imv2.setLayoutParams(new LinearLayout.LayoutParams(50,50)); setTitle("height:"+imv1.getLayoutParams().width+"\nwidth"+imv1.getLayoutParams().width) ; } }
相关推荐
huha 2020-10-16
xfcyhades 2020-11-20
sgafdsg 2020-11-04
Michael 2020-11-03
fengyeezju 2020-10-14
ziyexiaoxiao 2020-10-14
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28