当前位置: 首页 > 知识库问答 >
问题:

卡视图中的layout_margin无法正常工作

颛孙嘉玉
2023-03-14

我在玩新的CardView,但是利润似乎不适用。

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:layout_marginLeft="18dp"
android:layout_marginRight="18dp"
card_view:cardCornerRadius="4dp"
card_view:cardBackgroundColor="#FFA"
card_view:layout_margind="4dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

<TextView
    android:id="@+id/info_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"/>

</LinearLayout>

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

顺便说一句,我在视图页程序中的片段中使用它。该卡扩展了屏幕的整个宽度(match_parent),即使我在卡视图上使用Android:layout_marginLeft=“18dp”Android:layout_marginRight=“18dp”

你知道我可能做错了什么吗?

共有3个答案

陈业
2023-03-14

ViewPager。LayoutParams不扩展ViewGroup.MarginLayoutParams

就这么简单。

http://developer.android.com/reference/android/support/v4/view/ViewPager.LayoutParams.html

尤博达
2023-03-14

我以前也遇到过同样的问题,我在这里找到了答案… CardViewlayout_width="match_parent"与父RecyclerView宽度不匹配

在ViewPager中充气CardView xml时,将ViewGroup传递到其中。这将允许充气器知道要引用哪些布局参数。

要膨胀布局文件,请使用如下所示的内容:

View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.view_list_item, viewGroup,false);

希望有所帮助

尹昂雄
2023-03-14

如果使用RecyclerView添加CardView,android:layout_margin就足够了。

但是使用ListView添加CardView,您可能会这样做:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="11dp"
    android:layout_marginRight="11dp"
    android:layout_marginTop="11dp">
       (other layout ...)
</android.support.v7.widget.CardView>

</FrameLayout>

但它通常不是最佳的。

 类似资料:
  • 只是检查主活动. xml我正在做的是在按钮下方显示回收器视图并编辑文本...编辑文本的值被制成卡片,但问题是按钮不工作我不知道为什么请帮助 我是新的协调员的意见,所以请原谅我,如果我做一些新手的错误 AdapterEx.java 初始化回收器视图 主活动. xml 卡片视图. xml

  • 我在列表视图中使用微调器,但它在列表视图中不能正常工作。我能够在微调器中显示所需的值,但无法从微调器中获取选定的项目值。 它没有打印任何东西。布局:

  • 我正在尝试创建一个简单的照片库,其中一张照片是大的,也有拇指在底部,当点击成为那张大照片。画廊在单独的模式窗口。我的代码只在第一个模态窗口中工作。事实上,这是我第一次使用jQuery。我甚至找不到如何使用console.log来检查问题出在哪里。 HTML: jQuery:

  • 我写了一个日历视图的程序,它不能正常工作,因为我想要。首先,我有一个按钮,当点击打开一个新的活动,里面有一个线性布局,我有3个日月年的文本视图,我有一个对话框打开点击线性布局,因为我说我有3个文本视图在我的线性布局,而不是使用三个不同的点击监听器,我使用了在线性布局ID的帮助下点击,所以我的日历对话框打开了,但当我使用calendar.setOnDateChangeListener我的应用程序崩溃

  • 问题内容: 我在Java中使用以下使用selenium的代码。我要添加4秒的pageLoadTimeout,但是,驱动程序将继续等待,直到整个页面加载完毕。有什么帮助吗? 问题答案: 解决该 问题的方法是将您的 版本升级到 v3.5.0 。这是有效的代码块,并且使用 最少的代码即可生成您自己的代码: 代码块: 控制台输出: 捕获WebDriverException 代码块: 控制台输出:

  • 问题内容: 尽管我很确定这是昨天或前一天工作的,例如,在IE10中不再起作用。我已经测试了我的浏览器,但是它不再起作用了。还有谁有相同的问题吗?或者,它永远都行不通吗? 问题答案: IE不支持输入type =“ number”,但您可以使用jQueryUISpinner小部件。它非常易于使用,并且具有许多对开发人员友好的API。