1.实现的效果如图所示:文字代表用户输入的对自己的个人介绍,两张图片随着文字的增加,始终排列在个人介绍的右边
效果看起来没有什么难度,不过写起来的时候,着实费了脑筋,一小伙伴对这样一个布局,用起来多分辨率适配的方案,想想就觉得。。。
这个布局只要抓住一点:别让两个图片被文字挤出图片即可。
第一,你不能设置图片固定在右边,因为它是随文字动的
第二,文字是根据屏幕来的,你不管设置为wrap还是match都会把图片挤出屏幕
先来一个麻烦的实现方案
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/home_my_center_username_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:maxWidth="@dimen/home_my_center_name_txt_width"
android:text="dassssssssssssssssdassssssssssssssssssssss"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/common_txt_big_size" />
<ImageView
android:id="@+id/home_my_center_gender_img"
android:layout_width="@dimen/home_my_center_gender_img_height"
android:layout_height="@dimen/home_my_center_gender_img_height"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/home_my_center_gender_img_margin_left"
android:layout_marginStart="@dimen/home_my_center_gender_img_margin_left"
android:src="@mipmap/account_male_ic" />
<ImageButton
android:id="@+id/home_my_center_edit_img"
android:layout_width="@dimen/home_my_center_gender_img_height"
android:layout_height="@dimen/home_my_center_gender_img_height"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/home_my_center_edit_img_margin_left"
android:layout_marginStart="@dimen/home_my_center_edit_img_margin_left"
android:background="@android:color/white"
android:src="@mipmap/cpattern_1" />
</LinearLayout>
这个方案你需要对maxWidth分辨率单独适配
这是目前我觉得简单的:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/home_my_center_username_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:maxLines="1"
android:paddingEnd="@dimen/home_my_center_name_txt_padding_end"
android:text="@string/account_unknown_name"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/common_txt_big_size" />
<ImageView
android:id="@+id/home_my_center_gender_img"
android:layout_width="@dimen/home_my_center_gender_img_height"
android:layout_height="@dimen/home_my_center_gender_img_height"
android:layout_gravity="center_vertical|end"
android:layout_marginEnd="@dimen/home_my_center_gender_img_margin_end"
android:src="@mipmap/account_male_ic" />
<ImageView
android:id="@+id/home_my_center_edit_img"
android:layout_width="@dimen/home_my_center_gender_img_height"
android:layout_height="@dimen/home_my_center_gender_img_height"
android:layout_gravity="center_vertical|end"
android:background="@android:color/white"
android:src="@mipmap/edit" />
</FrameLayout>
FrameLayout中设置包裹内容,textVIew设置为包裹内容,那么整个布局相当于交给了textVIew,他想多大就多大,这样设置两个imge在它的布局中撒野就可以了
通过这篇文章,顺便规范一下自己对res目录下名称的规范