Card View在5.1.1 Tablet和5.0.2移动设备中不正确 [英] Card View not proper in 5.1.1 Tablet and 5.0.2 Mobile Device

查看:87
本文介绍了Card View在5.1.1 Tablet和5.0.2移动设备中不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用 CardView 创建以下视图。
添加依赖项 compile'c​​om.android.support:cardview- v7:23.0。+'在gradle依赖中


以下是相同的xml文件。


I am having the following view created with CardView .
Adding dependency compile 'com.android.support:cardview-v7:23.0.+' in gradle dependency

Below is the xml file for the same.

<android.support.v7.widget.CardView
                xmlns:card_view="http://schemas.android.com/apk/res-auto"
                android:id="@+id/cardViewEmp"
                android:layout_height="wrap_content"
                android:layout_width="0dp"
                android:layout_weight="0.50"
                card_view:cardCornerRadius="20dp"
                card_view:cardElevation="10dp"
                android:padding="@dimen/margin_10"
                >
                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    >
                <ImageView
                    android:id="@+id/employeeIcon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingTop="@dimen/margin_5"
                    android:src="@drawable/employeeicon"
                    android:layout_centerHorizontal="true"
                    />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Employee"
                    android:layout_centerHorizontal="true"
                    android:layout_below="@+id/employeeIcon"
                    android:textSize="@dimen/textSizeNormal"
                    />
                </RelativeLayout>
            </android.support.v7.widget.CardView>


            <android.support.v7.widget.CardView
                xmlns:card_view="http://schemas.android.com/apk/res-auto"
                android:id="@+id/cardViewVehicle"
                android:layout_height="wrap_content"
                android:layout_width="0dp"
                android:layout_weight="0.50"
                card_view:cardCornerRadius="20dp"
                card_view:cardElevation="10dp"
                android:padding="@dimen/margin_10"
                >
                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    >
                    <ImageView
                        android:id="@+id/vehicleIconLive"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingTop="@dimen/margin_5"
                        android:src="@drawable/vehicleicon"
                        android:layout_centerHorizontal="true"
                        />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Vehicle"
                        android:layout_centerHorizontal="true"
                        android:layout_below="@+id/vehicleIconLive"
                        android:textSize="@dimen/textSizeNormal"
                        />
                </RelativeLayout>
                </android.support.v7.widget.CardView>

现在4.4.4移动版中视图的高程和外观如下所示,好!




但在5.1.1 Nexus Tablet和5.0.2 Mobile中,这看起来很奇怪在下面。

Now the elevation and look and feel for the view in 4.4.4 mobile is as shown below which looks good !


But the same looks very odd in 5.1.1 Nexus Tablet and 5.0.2 Mobile as shown below.

我为此添加了海拔和转角半径

I have added elevation and corner radius by this

card_view:cardCornerRadius="20dp"
card_view:cardElevation="10dp"




  • 没有适当的抬高,任何人都可以清楚地看到拐角半径看起来很奇怪。

  • 可能是问题所在。

  • 可以做些什么来使CardView保持正确的外观和感觉

  • 编辑1:

    尝试使用 com.android.support:cardview-v7:23.1.1 ,但输出再次相同。

    Edit 1:
    Tried with com.android.support:cardview-v7:23.1.1 , but the output was same again.

    推荐答案

    最后,我发现了问题所在。这是因为我写了外面的 LinearLayout 使屏幕中心的图标高度为 wrap_content 。我避免使用 LinearLayout ,并通过以下代码,使卡视图具有适当的仰角曲线并在中间。

    Finally I figured out the issue. It was due to the outer LinearLayout I had written to make the icons in center of screen which was having height as wrap_content. I avoided the LinearLayout and through the following code, I made the card view with proper elevation curves and in middle .

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/mainRL"
            >
    <android.support.v4.widget.Space
                    android:layout_width="@dimen/margin_10"
                    android:layout_height="1dp"
                    android:layout_centerInParent="true"
                    android:layout_centerVertical="true"
                    android:id="@+id/spaceCenter"
                    />
    <!-- Employee icon -->
    
                <android.support.v7.widget.CardView
                    xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/cardViewEmp"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    card_view:cardCornerRadius="20dp"
                    card_view:cardElevation="10dp"
                    android:layout_toLeftOf="@+id/spaceCenter"
                    android:layout_centerInParent="true"
                    >
                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        >
                    <ImageView
                        android:id="@+id/employeeIcon"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:paddingTop="@dimen/margin_5"
                        android:src="@drawable/employeeicon"
                        android:layout_centerHorizontal="true"
                        />
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="  Employee  "
                        android:layout_centerHorizontal="true"
                        android:layout_below="@+id/employeeIcon"
                        android:textSize="@dimen/textSizeNormal"
                        />
                    </RelativeLayout>
                </android.support.v7.widget.CardView>
    
                <!-- Vehicle icon -->
    
                <android.support.v7.widget.CardView
                    xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/cardViewVehicle"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    card_view:cardCornerRadius="20dp"
                    card_view:cardElevation="10dp"
                    android:layout_toRightOf="@+id/spaceCenter"
                    android:layout_centerInParent="true"
                    >
                    <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        >
                        <ImageView
                            android:id="@+id/vehicleIconLive"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:paddingTop="@dimen/margin_5"
                            android:src="@drawable/vehicleicon"
                            android:layout_centerHorizontal="true"
                            />
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="    Vehicle     "
                            android:layout_centerHorizontal="true"
                            android:layout_below="@+id/vehicleIconLive"
                            android:textSize="@dimen/textSizeNormal"
                            />
                    </RelativeLayout>
                    </android.support.v7.widget.CardView>
    </RelativeLayout>
    

    这篇关于Card View在5.1.1 Tablet和5.0.2移动设备中不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆