textView布局的一点体会

时间:2023-03-10 07:04:04
textView布局的一点体会
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView android:id="@+id/img"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#00000000"
android:scaleType="fitCenter"
android:layout_margin="10dp"/> <TextView android:id="@+id/name"
android:textSize="40sp"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/> </LinearLayout>

listview的item,必须使用 android:layout_width="match_parent"
        android:layout_height="match_parent"/>

gravity才生效

ImageButton 是带图标的Button控件,有src的属性,也就是设置他的图标,也有一个所有控件公有的属性background, 这个也可以设置它的“图标”。
其实,src才是设置图标,而background只是设置背景。
如果控件的大小是100*100 图片资源是80*80的话,那么用src,图片就会居中显示,如果使用background那么图片就会被拉伸充满控件。
重要的是,background是底层的图片资源,src是覆盖在background上面的资源,他们可以叠加使用,实现选中的效果。在ActivityGroup用到。