观看次数持续增加

时间:2018-10-09 10:14:23

标签: android android-linearlayout android-imageview android-relativelayout

我有3个视图,2个TextViews和1个ImageView。我希望视图像下面这样一个接一个地对齐:-

此处的“ +”号是ImageView,第二个TextView是“另一个文本”。 enter image description here

我尝试使用水平方向的LinearLayout。同样是RelativeLayout,但是显示第一个TextView,但是不显示下一个ImageView和TextView。

<android.support.v7.widget.LinearLayoutCompat
            style="@style/style_ww"
            android:orientation="horizontal">

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/txtusername"
                style="@style/style_ww"
                android:text="jjjkcrhwkjehrckwjherkjwherckjwhekrcjwernwjkrncwjknrkwjncwjrnwkjcnkwjnrckwjnrkwjnrkwjcncrkjwnrkjcwnrnwkrcnkwnrkwnrckwjnrkwjncrknwkrjnckwnrkwjnrkcwnrkwnckjnrkwnrkwnrckwnrkwnrckwrn"
                android:textColor="@color/colorBlueGrey400"
                android:textSize="@dimen/size_fourteen"
                app:fontFamily="@font/roboto"/>

            <android.support.v7.widget.AppCompatImageView
                android:id="@+id/plus"
                android:layout_width="@dimen/value_2"
                android:layout_height="@dimen/value_2"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="@dimen/value_5"
                android:layout_marginTop="@dimen/value_1"
                android:src="@drawable/ic_plus"/>

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/tvcomment"
                style="@style/style_ww"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="@dimen/value_5"
                android:layout_marginRight="@dimen/value_20"
                android:text="@string/comment"
                android:textColor="@color/colorBlueGrey400"
                app:fontFamily="@font/roboto"/>

        </android.support.v7.widget.LinearLayoutCompat>

style / style_ww

<style name="style_ww">
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_width">wrap_content</item>
</style>

我该如何实现?感谢您的帮助

1 个答案:

答案 0 :(得分:0)

感谢Nilesh Rathod的解决方案

tvText = findViewById(R.id.tvText); 


SpannableStringBuilder spannableStringBuilder= new SpannableStringBuilder(); 
Spannable span = new SpannableString("Please press the button looking like this and then proceed .."); 
Drawable test = getResources().getDrawable(R.drawable.ic_delete); 
test.setBounds(0, 0, 32,32); 
ImageSpan imageSpan = new ImageSpan(test, ImageSpan.ALIGN_BASELINE); 
span.setSpan(imageSpan, span.length()-2, span.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); 
spannableStringBuilder.append(span); 
spannableStringBuilder.append("Second Span"); 


tvText.setText(spannableStringBuilder);