2015-12-19 62 views
1

我有一个包含水平回收视图的活动。 现在的主要问题是我想要有一个评论布局,就像屏幕底部没有填充父项的应用程序一样。查看未填充父项

活动布局:在回收鉴于

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_view_mood_detail_activity" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 

</RelativeLayout> 

行观点:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    > 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
     <LinearLayout 
      android:id="@+id/row_layout" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/margin_large" 
      android:layout_marginRight="@dimen/margin_large" 
      > 

      <ImageView 
       android:id="@+id/quote_image_mood_detail_activity" 
       android:layout_width="fill_parent" 
       android:layout_height="300dp" 
       android:scaleType="centerCrop" 
       /> 
      <include 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       layout="@layout/layout_like_and_share" 
       android:layout_gravity="right" 
       /> 
      <com.ascentbrezie.brezie.custom.CustomTextView 
       android:id="@+id/comments_count_text_mood_detail_activity" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textSize="@dimen/text_size_small" 
       android:layout_margin="@dimen/margin_small" 
       /> 
      <LinearLayout 
       android:id="@+id/display_comments_layout_mood_detail_activity" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" 
       android:layout_margin="@dimen/margin_small" 
       /> 

      <include 
       android:id="@+id/abc" 
       layout="@layout/layout_add_comments" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       /> 

     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

当我使用以上两个代码我有输出this

但我想设置编辑文本和布局按钮处的按钮作为页脚,为此,当我使用此布局时。

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    > 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
     <LinearLayout 
      android:id="@+id/row_layout" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="@dimen/margin_large" 
      android:layout_marginRight="@dimen/margin_large" 
      > 

      <ImageView 
       android:id="@+id/quote_image_mood_detail_activity" 
       android:layout_width="fill_parent" 
       android:layout_height="300dp" 
       android:scaleType="centerCrop" 
       /> 
      <include 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       layout="@layout/layout_like_and_share" 
       android:layout_gravity="right" 
       /> 
      <com.ascentbrezie.brezie.custom.CustomTextView 
       android:id="@+id/comments_count_text_mood_detail_activity" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textSize="@dimen/text_size_small" 
       android:layout_margin="@dimen/margin_small" 
       /> 
      <LinearLayout 
       android:id="@+id/display_comments_layout_mood_detail_activity" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" 
       android:layout_margin="@dimen/margin_small" 
       /> 

     </LinearLayout> 
    </ScrollView> 

    <include 
     android:id="@+id/abc" 
     layout="@layout/layout_add_comments" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     /> 

</RelativeLayout> 

现在的问题是我得到的XML预览完全符合我的要求。看看[这里],但是当我在任何设备上运行应用程序时,我会得到像this这样的输出。

所以主要的问题是页脚布局不能拉伸填充父窗口并在屏幕右侧留下一些空间。我也为整个视图动态设置了边距。

RowLayout是滚动视图内的线性布局。卡宽度是屏幕的

rowLayout = (LinearLayout) holder.v.findViewById(R.id.row_layout); 

FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(cardWidth, ViewGroup.LayoutParams.FILL_PARENT); 
layoutParams.setMargins(10, 10, 0, 0); 
rowLayout.setLayoutParams(layoutParams); 
+0

宽度为什么你不能在布局文件本身添加的利润?也可以尝试使用'android:layout_weight = 1'并为您要填充父级的控件设置'android:layout_width =“0dp”'。 – AndroidMechanic

+0

将布局宽度设置为0dp和重量,因为我希望布局中的两个项目根据可用空间分配自己 – jigar

回答

0

这应该这样做

<LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"><EditText android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button"/></LinearLayout>