Cardslib - unwanted 12dp margin on all cards

十年热恋 提交于 2019-12-08 04:57:08

问题


Summary: I’m new to Android development, and I’m using Gabriele Mariotti's excellent cardslib to display images (.jpgs) on cards. I want the image to cover the entire card with no margin. Instead, I’m seeing an unwanted 12dp margin on all sides of the image. I’ve tried various things, but I’ve been unable to remove this margin (in other words, set the margin to 0dp).

Details: I’m displaying a .jpg on a card. The .jpg is the only thing on the card (that is, no header, no thumbnail, etc.) The problem is that extra whitespace appears on all sides of the card. Depending on the relative aspect ratios of the .jpg and the card, there is more whitespace on either the top/bottom or left/right edges, but at the minimum the whitespace is exactly 12dp.

Looking at the documentation, in particular the CARD documentation, it seemed I should set things like layout_marginTop and layout_marginBottom. I tried a number of different permutations of these, but could not remove the 12dp margin. My layouts currently look like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="0dp"
    android:layout_marginTop="0dp"
    android:layout_marginBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    android:paddingBottom="0dp" >

    <it.gmariotti.cardslib.library.view.CardViewNative
        android:id="@+id/carddemo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="0dp"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:paddingTop="0dp"
        android:paddingBottom="0dp" />
</LinearLayout>

and

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_marginTop="0dp"
    android:layout_marginBottom="0dp"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="238dp">

    <ImageView
        android:layout_marginTop="0dp"
        android:layout_marginBottom="0dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"/>
</LinearLayout>

(I realize many of the above settings are redundant, unnecessary or silly. After I found the correct one(s) I was going to prune out the unnecessary ones.)

I searched the stackoverflow "cardslib" tag for "margin" (1 hit), "marginTop" (0 hits), "padding" (1 hit), "layout" (25 hits) but didn't find the solution in any of those answers.


回答1:


Check this file.

In your case, you can override these values in your project:

    <dimen name="card_main_content_native_default_paddingLeft">12dp</dimen>
    <dimen name="card_main_content_native_default_paddingRight">12dp</dimen>
    <dimen name="card_main_content_native_default_paddingTop">12dp</dimen>
    <dimen name="card_main_content_native_default_paddingBottom">12dp</dimen>


来源:https://stackoverflow.com/questions/29134528/cardslib-unwanted-12dp-margin-on-all-cards

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!