2017-04-25 56 views
-2

我在片段中使用RecyclerView。我想要片段在宽度和高度上匹配父项。但这是我的输出。删除片段中的边距

My output

周围有一个片段被留下了空间。我想消除这一点。我尝试了一切,即使用父容器将第三个参数设置为false,将LayoutParams更改为match_parent,但没有任何工作。

我的代码: -

fragment.xml之

<?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:id="@+id/RLGEVENT" 
android:background="@color/white"> 

<android.support.design.widget.FloatingActionButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    android:clickable="true" 
    android:layout_marginLeft="16dp" 
    android:layout_marginBottom="16dp" 
    android:layout_marginRight="16dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentEnd="true" 
    android:src="@drawable/postbutton" 
    android:id="@+id/floatingButton" /> 

<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/listView" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 

    /> 

片段

@Override 
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 


    view = inflater.inflate(R.layout.activity_gevent_main, container, false); 

    RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.RLGEVENT); 
    rl.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); 
    rl.invalidate(); 

    //code   

    return view; 
} 

的ROOT.xml

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v4.widget.DrawerLayout       
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

<include 
    layout="@layout/app_bar_start" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:background="@color/white" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:insetForeground="@color/white" 
    android:theme="@style/AppTheme.Lolwa" 
    app:headerLayout="@layout/nav_header_start" 
    app:itemTextColor="@color/black" 
    app:menu="@menu/activity_start_drawer" /> 

    </android.support.v4.widget.DrawerLayout> 

Row.xml

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:id="@+id/card_view" 
    android:layout_height="wrap_content"> 

    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/gEventRowRL" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:background="#fff"> 


     <ImageView 
      android:id="@+id/exampleProfilePic" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:layout_marginLeft="10dp" 
      android:scaleType="fitXY" 
      android:src="@drawable/background_profile_pic" /> 

     <ImageView 
      android:id="@+id/photoOf" 
      android:layout_width="match_parent" 
      android:layout_height="400dp" 
      android:layout_below="@+id/gEventsDetails" 
      android:scaleType="fitXY" 
      android:src="@drawable/black_total" /> 


     <TextView 
      android:id="@+id/geventTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:layout_toRightOf="@+id/exampleProfilePic" 
      android:text="Title" 
      android:textSize="18sp" 

      /> 

     <TextView 
      android:id="@+id/gEventsDetails" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/exampleProfilePic" 
      android:layout_margin="10dp" 
      android:text="" 
      android:textSize="16sp" /> 


     <TextView 
      android:id="@+id/gEventsDescription" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/geventTitle" 
      android:layout_margin="10dp" 
      android:layout_toRightOf="@+id/photoOf" 
      android:text="" /> 


    </RelativeLayout> 

    </RelativeLayout> 

app_bar_start.xml

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="com.example.anubhavr.firebase.StartActivity"> 

    <android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_start" /> 


</android.support.design.widget.CoordinatorLayout> 

活动

@Override 
    protected void onCreate(Bundle savedInstanceState) { 

    setTheme(R.style.AppTheme); 

    super.onCreate(savedInstanceState); 
    overridePendingTransition(R.anim.slide_in, R.anim.slide_out); 

    setContentView(R.layout.activity_start); 

    fragmentManager = getSupportFragmentManager(); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
      this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 
    drawer.setDrawerListener(toggle); 
    toggle.syncState(); 

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 
    navigationView.setNavigationItemSelectedListener(this); 


    com.example.anubhavr.firebase.Global_Events.MainActivity mainActivity = new com.example.anubhavr.firebase.Global_Events.MainActivity(); 
    setListener(mainActivity); 

    fragmentManager.beginTransaction().replace(R.id.nav_home, mainActivity, mainActivity.getTag()).commit(); 


} 
+0

后根布局,将被加入该片段至。 – azizbekian

+0

同时发布回收者视图的行 –

+0

后也'app_bar_start.xml'。 – azizbekian

回答

1

的填充应该在content_start

+0

在任何资源文件中都没有应用填充。您在说什么填充?先生? – THGRoy

+0

你在app_bart_start里面有 content_start是一个xml布局,我在你的问题中看不到它,也许我很想念它。但对于我看到你的片段应该在里面。 – cutiko