В макете слишком много просмотров - PullRequest
0 голосов
/ 05 мая 2020

В настоящее время я пытаюсь создать приложение на основе регистров ca sh с сеткой 5x5 для отображения всего меню. Я использовал GridLayout с CardView для их отображения. 1 CardView с linearLayout + Imageview + TextView дал всего 4 просмотра, поэтому 5x5 cardview сделал мой xml в итоге 100 просмотров ...

Я попытался использовать теги include для linearlayout + imageview + textview внутри cardview , в результате чего количество просмотров упало до 50. Но теперь проблема заключается в следующем: я бы хотел изменить текст и изображение src внутри тегов include, иначе я не смогу отобразить все изображения меню. Возможно ли это вообще?

Есть предложения по поводу моих проблем?

            <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginStart="16dp"
            app:cardPreventCornerOverlap="true"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">
            <LinearLayout android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:weightSum="100"
                android:orientation="vertical"
                >
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:scaleType="centerCrop"
                    android:layout_gravity="center"
                    android:layout_weight="70"
                    android:src="@drawable/noimage"
                    android:contentDescription="@string/logo" />
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:textSize="18sp"
                    android:textColor="#A9A9A9"
                    android:layout_weight="30"
                    android:textAlignment="center"
                    android:autoSizeTextType="uniform"
                    android:text="@string/logo"/>
            </LinearLayout>


        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_columnWeight="1"
            android:layout_rowWeight="1"
            android:layout_marginBottom="16dp"
            android:layout_marginStart="16dp"
            app:cardPreventCornerOverlap="true"
            app:cardElevation="8dp"
            app:cardCornerRadius="8dp">
            <include layout="@layout/menu_cardview"/>

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

1 Ответ

0 голосов
/ 05 мая 2020

Я думаю, что в настоящее время это невозможно, но то, что вы можете сделать, чтобы уменьшить / оптимизировать свой код xml, - это Первый вариант:

используйте только TextViews в GridLayout, а для изображений над ними не используйте отдельные ImageView. это в TextViews android:drawabkeTop="drawable/image

Второй вариант:

Второй вариант, который вы также можете использовать вместе с первым вариантом. Используйте стили для стилизации вашего макета Пример:

 <style name="gridImageStyle">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:src">@drwable/image</item>
</style>

<style name="gridTextStyle">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textSize">20sp</item>
    <item name="android:textColor">20sp</item>
</style>

и используйте его в TextView и ImageView следующим образом

              <TextView
                    style="@style/gridTextStyle"
                    android:text="EnterTextHere"/>

              <ImageView
                    style="@style/gridImageStyle"
                    android:src="Enter Image Source here"/>

Но я бы рекомендовал вам использовать android:drawableTop:"ImageSource" в TextView вместо ImageView

...