Android:控件的对象修改控件的值

时间:2021-05-18 00:23:40

TextView

private TextView textView;
...
textView =(TextView)findViewById(R.id.textView);
textView.setText("set text success");

控制:

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ff0000"
android:text="old text"
/>

ImageView

 imageViewId1 =(ImageView)findViewById(R.id.imageViewId1);
imageViewId1.setImageResource(R.drawable.logo_small);
imageViewId1.setScaleType(ScaleType.CENTER);
<ImageView
android:id="@+id/imageViewId1"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="@drawable/pic1"
android:scaleType="fitXY"
android:background="#ff0000"
/>