如何实现如下截图的布局

时间:2017-12-13 06:40:02

标签: android

enter image description here

在这个布局中,我首先想要imageView然后是textView,然后一旦我完成textView,我想添加imageView,我该怎么做。

3 个答案:

答案 0 :(得分:1)

试试这个

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher_round" />

    <TextView
        android:id="@+id/MyTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toEndOf="@id/img"
        android:gravity="center"
        android:text="NILU" />   


</RelativeLayout>

使用textviewImageSpan末尾设置Imageview,使用以下代码

 textView = (TextView) findViewById(R.id.MyTextView);
 Spannable span = new SpannableString("nilu  ");
 Drawable demo = getResources().getDrawable(R.mipmap.ic_launcher);
 demo.setBounds(0, 0, 50, 50);
 ImageSpan image = new ImageSpan(demo, ImageSpan.ALIGN_BASELINE);
 span.setSpan(image,span.length()-1,span.length(),Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
 textView.setText(span);

<强>输出 enter image description here

答案 1 :(得分:0)

使用此

 android:drawableRight="R.drawabal/xyz"

答案 2 :(得分:0)

只需将其添加到布局文件中

即可
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.android.stackoverflow.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:text="This is your sample text where you can add any 
     description" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />
</LinearLayout>