Как отобразить изображение внутри карты в макете? - PullRequest
0 голосов
/ 18 мая 2019

Я сделаю 6 просмотров карт с изображением в них. Мой код был успешно запущен на Android Nougat (api 25), но когда я запускаю на Android Kitkat (api 21), изображение не отображается.

cardview

<android.support.v7.widget.CardView
                    android:id="@+id/cardWJ"
                    android:layout_width="10dp"
                    android:layout_height="10dp"
                    android:layout_rowWeight="1"
                    android:layout_columnWeight="1"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginBottom="16dp"
                    app:cardCornerRadius="8dp"
                    app:cardElevation="8dp">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_horizontal|center_vertical"
                        android:layout_margin="5dp"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="match_parent"
                            android:layout_height="80dp"
                            android:layout_gravity="center_horizontal"
                            android:src="@drawable/icon_news" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:gravity="center_horizontal"
                            android:text="Warta"
                            android:textColor="@android:color/black"
                            android:textSize="12sp"
                            android:textStyle="bold" />
                    </LinearLayout>
                </android.support.v7.widget.CardView>

Ответы [ 2 ]

0 голосов
/ 18 мая 2019

Сначала ширина и высота вашей карты должны быть обернутыми, а не 10dp, 10dp соответственно.Ваше изображение больше, чем ваша карта

Для большей наглядности перейдите по этой ссылке https://www.dev2qa.com/android-cardview-with-image-and-text-example/

0 голосов
/ 18 мая 2019

Ваш рост и ширина карты очень малы, вам нужно это изменить.

<android.support.v7.widget.CardView
                    android:id="@+id/cardWJ"
                    android:layout_width="10dp"
                    android:layout_height="10dp"

либо:

               android:layout_height="wrap_content"
               android:layout_width="wrap_content"

или

              android:layout_width="80dp"
              android:layout_height="80dp"

зависит от вашего выбора. Надеюсь, это поможет вам.

...