【发布时间】:2016-02-08 22:38:18
【问题描述】:
我正在关注本教程http://www.androidhive.info/2014/06/android-facebook-like-custom-listview-feed-using-volley/。我复制了这个布局:
recycler_items:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="@dimen/feed_item_margin"
android:layout_marginRight="@dimen/feed_item_margin"
android:layout_marginTop="@dimen/feed_item_margin"
android:background="@drawable/bg_parent_rounded_corner"
android:orientation="vertical"
android:paddingBottom="@dimen/feed_item_padding_top_bottom"
android:paddingTop="@dimen/feed_item_padding_top_bottom" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="@dimen/feed_item_padding_left_right"
android:paddingRight="@dimen/feed_item_padding_left_right" >
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/profilePic"
android:layout_width="@dimen/feed_item_profile_pic"
android:layout_height="@dimen/feed_item_profile_pic"
android:scaleType="fitCenter" >
</com.android.volley.toolbox.NetworkImageView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/feed_item_profile_info_padd" >
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/feed_item_profile_name"
android:textStyle="bold" />
<TextView
android:id="@+id/timestamp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/timestamp"
android:textSize="@dimen/feed_item_timestamp" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/txtStatusMsg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingLeft="@dimen/feed_item_status_pad_left_right"
android:paddingRight="@dimen/feed_item_status_pad_left_right"
android:paddingTop="@dimen/feed_item_status_pad_top" />
<TextView
android:id="@+id/txtUrl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:linksClickable="true"
android:paddingBottom="10dp"
android:paddingLeft="@dimen/feed_item_status_pad_left_right"
android:paddingRight="@dimen/feed_item_status_pad_left_right"
android:textColorLink="@color/link" />
<info.androidhive.listviewfeed.FeedImageView
android:id="@+id/feedImage1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:scaleType="fitXY"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
出于某种原因,我在右侧有额外的空白,例如屏幕的 1/5。当我在应用程序中预览它时不存在,但在手机上它是。我知道问题出在这种布局上,因为如果我只用图像替换所有内容,它将填满整个宽度。这是一张有问题的图片:http://6pix.net/images/89726012394405680403.jpg。多余的空间从何而来?
这是我的回收站:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/recycler_view"
/>
</LinearLayout>
这就是我为 recyclerItems 充气的方式:
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recycler_items, null);
【问题讨论】:
-
如果您使用 FAB 按钮,您必须使用 CoordinatorLayout。要解决此问题,请将您的 LinearLayout 放入 android 设计支持库中的 CoordinatorLayout 中。使用此网址获取更多信息developer.android.com/reference/android/support/design/widget/…
-
此布局用于
recyclerView,它位于一个片段中,该片段位于使用 CoordinatorLayout 的布局中。 -
检查您声明 FAB 的代码。那里可能有问题。
-
不是。我什至删除了 fab 按钮,空间仍然存在。我确信空间来自这种布局。正如我所说,如果我从这个布局中删除除了 FeedImageView(或任何其他元素)之外的所有内容,它们将具有全宽。
-
出了点问题,但我不知道是哪一部分
标签: android android-layout android-studio android-linearlayout