Как установить панель инструментов виджета с 4 кнопками после каждого просмотра текста - PullRequest
0 голосов
/ 27 октября 2018

Я разрабатываю приложение для цитат, и у меня так много цитат на одной странице (мероприятие), поэтому я хочу панель инструментов виджетов и 4 кнопки общего доступа после каждого просмотра текста, я сделал это через xml, я хочу сделать это с помощью кодирования в Java-активность, поэтому длина кода будет уменьшена, пожалуйста, дайте мне правильное решение для этого и, пожалуйста, посмотрите эти картинки и мой код

Изображение

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    tools:context="technoapps4.shayari_vayari.second">

    <ScrollView
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            tools:layout_editor_absoluteY="0dp"
            tools:layout_editor_absoluteX="8dp">

            <TextView
                android:id="@+id/textView"
                android:onClick="tv"
                android:text="@string/Funny1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="10dp"
                android:textColor="#fff"
                android:textIsSelectable="true"
                android:textSize="20sp"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/tb"
          android:layout_width="match_parent"
            android:layout_marginTop="05dp"
            android:layout_height="match_parent"
            android:background="#fff">
        </android.support.v7.widget.Toolbar>

            <Button
                android:id="@+id/copy1"
                android:onClick="copy1"
                android:layout_marginLeft="08dp"
                android:layout_marginTop="-50dp"
                android:layout_width="56dp"
                android:layout_height="46dp"
                android:background="@drawable/copy" />

                <Button
                android:id="@+id/whatsapp1"
                android:onClick="whatsapp1"
                android:layout_marginLeft="90dp"
                android:layout_marginTop="-48dp"
                android:layout_width="56dp"
                android:layout_height="46dp"
                android:background="@drawable/whatsapp" />

            <Button
                android:id="@+id/fb1"
                android:onClick="fb1"
                android:layout_marginLeft="180dp"
                android:layout_marginTop="-46dp"
                android:layout_width="56dp"
                android:layout_height="46dp"
                android:background="@drawable/facebook" />


            <Button
                android:id="@+id/share1"
                android:onClick="share1"
                android:layout_marginLeft="275dp"
                android:layout_marginTop="-46dp"
                android:layout_width="56dp"
                android:layout_height="46dp"
                android:background="@drawable/share" />


            <TextView
                android:id="@+id/textView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:text="@string/Funny2"
                android:textColor="#fff"
                android:textIsSelectable="true"
                android:textSize="20sp" />

            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_marginTop="05dp"
                android:layout_height="match_parent"
                android:background="#fff">
            </android.support.v7.widget.Toolbar>

            <Button
                android:id="@+id/copy2"
                android:onClick="copy2"
                android:layout_marginLeft="08dp"
                android:layout_marginTop="-50dp"
                android:layout_width="56dp"
                android:layout_height="46dp"
                android:background="@drawable/copy" />

            <Button
                android:id="@+id/what2"
                android:onClick="whatsapp2"
                android:layout_marginLeft="90dp"
                android:layout_marginTop="-48dp"
                android:layout_width="56dp"
                android:layout_height="46dp"
                android:background="@drawable/whatsapp" />

            <Button
                android:id="@+id/fb2"
                android:layout_marginLeft="180dp"
                android:onClick="fb2"
                android:layout_marginTop="-46dp"
                android:layout_width="56dp"
                android:layout_height="46dp"
                android:background="@drawable/facebook" />

            <Button
                android:id="@+id/share2"
                android:onClick="share2"
                android:layout_marginLeft="275dp"
                android:layout_marginTop="-46dp"
                android:layout_width="56dp"
                android:layout_height="46dp"
                android:background="@drawable/share" />



        </LinearLayout>

    </ScrollView>

</android.support.constraint.ConstraintLayout>

1 Ответ

0 голосов
/ 27 октября 2018

Если у вас будет много котировок, я предлагаю вам использовать RecyclerView вместе с RecyclerView.Adapter.LinearLayout может замедлить ваше приложение.

Но если у вас не так много кавычек или вы действительно хотите использовать LinearLayout.Вы можете создать listitem_quote.xml, содержащий вашу цитату и сначала 4 кнопки.

А затем использовать пустой LinearLayout в своем activity.xml, как это.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:id="@+id/myLinearLayout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</ScrollView>

В своей деятельностиinflate() за каждые кавычки.И добавьте их в свой макет.

onCreate(...){
    setContentView(R.layout.activity_main);
    myLinearLayout = (LinearLayout) findViewById(R.id.myLinearLayout);
    LayoutInflater layoutInflater = LayoutInflater.from(this);
    for(...){ // for every quote
        // create a view for quote contains buttons
        View quoteView = layoutInflater.inflate(R.layout.listitem_quote, null);
        TextView tvQuote = quoteView.findViewById(...);
        tvQuote.setText(...);
        Button btn1 = quoteView.findViewById(...);
        btn1.setOnclickListener(...);
        myLinearLayout.addView(quote);// add to Linearlayout
    }
}

Это поможет.

Однако я все же предлагаю вам использовать RecyclerView вместо этого.Вы можете найти много примеров в Интернете.Это выглядит сложнее, но полезно.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...