简体   繁体   English

如何使按钮在可扩展文本视图中可见

[英]How to make button visible in expandable text view

in my activity I have a linear view with multiple scroll views in it, problem is I want a button to apear to the right of the text thats about to be expanded, bellow is my code for the expandable text view when i use android:src for the image in my drawables no happens though. 在我的活动中,我有一个带有多个滚动视图的线性视图,问题是我想在要展开的文本的右侧显示一个按钮,当我使用android:src时,波纹管是我的可扩展文本视图的代码对于我的绘画中的图像,虽然没有发生。

 <com.ms.square.android.expandabletextview.ExpandableTextView
                android:id="@+id/expandable_text_view1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"


                app:animDuration="200"
                app:maxCollapsedLines="1"

                >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"

                    >

                    <TextView
                        android:id="@+id/expandable_text"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:textSize="18sp"


                        />

                    <ImageButton

                        android:id="@+id/expand_collapse"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_gravity="bottom|end"
                        android:background="@android:color/transparent"
                        />

                </LinearLayout>

            </com.ms.square.android.expandabletextview.ExpandableTextView>

Try this code: 试试这个代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:padding="16dp">

    <com.ms.square.android.expandabletextview.ExpandableTextView
        android:id="@+id/expandable_text_view1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:animDuration="200"
        app:maxCollapsedLines="1">

        <TextView
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="8dp"
            android:textColor="@android:color/black"
            android:id="@+id/expandable_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp" />

        <ImageButton
            android:id="@+id/expand_collapse"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="bottom|end"
            android:background="@android:color/transparent" />

    </com.ms.square.android.expandabletextview.ExpandableTextView>
</LinearLayout>

To add your own custom image, add the following properties in your ExpandabaleTextView: 要添加您自己的自定义图像,请在ExpandabaleTextView中添加以下属性:

app:expandDrawable="@drawable/expand_image"
app:collapseDrawable="@drawable/collapse_image"

MainActivity: 主要活动:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.ms.square.android.expandabletextview.ExpandableTextView;

public class MainActivity extends AppCompatActivity {

    ExpandableTextView expandableTextView;
    String long_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        expandableTextView = (ExpandableTextView) findViewById(R.id.expandable_text_view1);
        expandableTextView.setText(long_text);

    }
}

Check out the Documentation for more help. 请查阅文档以获取更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM