简体   繁体   English

视图不全宽

[英]view not taking the full width

In my app i am using recyclerview.I want customize list data so i have made a custom adapter.Now the problem is that the view appears to be of full width in the preview window of android studio but on the device its not full width so my half data is getting cutted.在我的应用程序中,我正在使用 recyclerview。我想自定义列表数据,所以我制作了一个自定义适配器。现在的问题是,android studio 的预览窗口中的视图似乎是全宽的,但在设备上它不是全宽的,所以我的一半数据被削减了。

XMl 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="wrap_content"
    android:layout_marginBottom="2dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="2dp"
    android:background="#EDEFF1">


    <TextView
        android:id="@+id/tv_g_name"
        style="@style/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:padding="10dp"
        android:text="Ashton Kutcher" />

    <ImageView
        android:id="@+id/iv_g_del"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:padding="10dp"
        android:src="@drawable/ic_cancellation" />

    <TextView
        android:id="@+id/textView33"
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:layout_alignBottom="@+id/tv_g_name"
        android:layout_toLeftOf="@+id/iv_g_del"
        android:layout_toStartOf="@+id/iv_g_del"
        android:background="#D6D7D9" />

    <ImageView
        android:id="@+id/iv_g_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/textView33"
        android:layout_toStartOf="@+id/textView33"
        android:padding="10dp"
        android:src="@drawable/ic_cancellation" />

    <TextView
        android:id="@+id/textView34"
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:layout_alignBottom="@+id/textView33"
        android:layout_toLeftOf="@+id/iv_g_add"
        android:layout_toStartOf="@+id/iv_g_add"
        android:background="#D6D7D9" />

    <TextView
        android:id="@+id/textView35"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/iv_g_add"
        android:background="#D6D7D9" />

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/textView35"
        android:paddingBottom="05dp"
        android:paddingLeft="10dp"
        android:paddingRight="05dp"
        android:paddingTop="05dp"
        android:src="@drawable/ic_cancellation" />

    <TextView
        android:id="@+id/tv_g_email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView5"
        android:layout_below="@+id/textView35"
        android:layout_toEndOf="@+id/imageView5"
        android:layout_toRightOf="@+id/imageView5"
        android:gravity="center"
        android:text="pavanh.dev@gmail.com" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/tv_g_email"
        android:layout_toEndOf="@+id/tv_g_email"
        android:layout_toRightOf="@+id/tv_g_email"
        android:paddingBottom="05dp"
        android:paddingLeft="10dp"
        android:paddingRight="05dp"
        android:paddingTop="05dp"
        android:src="@drawable/ic_cancellation" />

    <TextView
        android:id="@+id/tv_g_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView6"
        android:layout_below="@+id/textView35"
        android:layout_toEndOf="@+id/imageView6"
        android:layout_toRightOf="@+id/imageView6"
        android:gravity="center"
        android:text="889845412" />
</RelativeLayout>

Please let me know where i went wrong?请让我知道我哪里出错了?

Use Padding in Parent instead of margin like below and also check padding and margin of your ListView which may stop View Rendering Full width在 Parent 中使用 Padding 而不是像下面这样的边距,并检查 ListView 的填充和边距,这可能会停止 View Rendering Full width

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:layout_paddingLeft="5dp"
        android:layout_paddingRight="5dp"
        android:layout_marginTop="2dp"
        android:background="#EDEFF1">
       <TextView
        android:id="@+id/tv_g_name"
        style="@style/text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:padding="10dp"
        android:text="Ashton Kutcher" />

    <ImageView
        android:id="@+id/iv_g_del"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:padding="10dp"
        android:src="@drawable/ic_cancellation" />

    <TextView
        android:id="@+id/textView33"
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:layout_alignBottom="@+id/tv_g_name"
        android:layout_toLeftOf="@+id/iv_g_del"
        android:layout_toStartOf="@+id/iv_g_del"
        android:background="#D6D7D9" />

    <ImageView
        android:id="@+id/iv_g_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/textView33"
        android:layout_toStartOf="@+id/textView33"
        android:padding="10dp"
        android:src="@drawable/ic_cancellation" />

    <TextView
        android:id="@+id/textView34"
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:layout_alignBottom="@+id/textView33"
        android:layout_toLeftOf="@+id/iv_g_add"
        android:layout_toStartOf="@+id/iv_g_add"
        android:background="#D6D7D9" />

    <TextView
        android:id="@+id/textView35"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/iv_g_add"
        android:background="#D6D7D9" />

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/textView35"
        android:paddingBottom="05dp"
        android:paddingLeft="10dp"
        android:paddingRight="05dp"
        android:paddingTop="05dp"
        android:src="@drawable/ic_cancellation" />

    <TextView
        android:id="@+id/tv_g_email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView5"
        android:layout_below="@+id/textView35"
        android:layout_toEndOf="@+id/imageView5"
        android:layout_toRightOf="@+id/imageView5"
        android:gravity="center"
        android:text="pavanh.dev@gmail.com" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/tv_g_email"
        android:layout_toEndOf="@+id/tv_g_email"
        android:layout_toRightOf="@+id/tv_g_email"
        android:paddingBottom="05dp"
        android:paddingLeft="10dp"
        android:paddingRight="05dp"
        android:paddingTop="05dp"
        android:src="@drawable/ic_cancellation" />

    <TextView
        android:id="@+id/tv_g_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView6"
        android:layout_below="@+id/textView35"
        android:layout_toEndOf="@+id/imageView6"
        android:layout_toRightOf="@+id/imageView6"
        android:gravity="center"
        android:text="889845412" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:background="#EDEFF1">

Try using fill_parent instead of match_parent尝试使用fill_parent而不是match_parent

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="2dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="2dp"
    android:background="#EDEFF1">

And in 1st TextView, you have forgotten mentioning the namespace android:style .在第一个 TextView 中,您忘记提及命名空间android:style Please rectify that.请改正。

try this,尝试这个,

<?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:layout_marginBottom="2dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="2dp"
    android:background="#EDEFF1">


    <TextView
        android:id="@+id/tv_g_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:padding="10dp"
        android:text="Ashton Kutcher" />

    <ImageView
        android:id="@+id/iv_g_del"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:padding="10dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView33"
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:layout_alignBottom="@+id/tv_g_name"
        android:layout_toLeftOf="@+id/iv_g_del"
        android:layout_toStartOf="@+id/iv_g_del"
        android:background="#D6D7D9" />

    <ImageView
        android:id="@+id/iv_g_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/textView33"
        android:layout_toStartOf="@+id/textView33"
        android:padding="10dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView34"
        android:layout_width="2dp"
        android:layout_height="match_parent"
        android:layout_alignBottom="@+id/textView33"
        android:layout_toLeftOf="@+id/iv_g_add"
        android:layout_toStartOf="@+id/iv_g_add"
        android:background="#D6D7D9" />

    <TextView
        android:id="@+id/textView35"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/iv_g_add"
        android:background="#D6D7D9" />

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignTop="@+id/textView35"
        android:paddingBottom="05dp"
        android:paddingLeft="10dp"
        android:paddingRight="05dp"
        android:paddingTop="05dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/tv_g_email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView5"
        android:layout_below="@+id/textView35"
        android:layout_toEndOf="@+id/imageView5"
        android:layout_toRightOf="@+id/imageView5"
        android:gravity="center"
        android:text="pavanh.dev@gmail.com" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/tv_g_email"
        android:layout_toEndOf="@+id/tv_g_email"
        android:layout_toRightOf="@+id/tv_g_email"
        android:paddingBottom="05dp"
        android:paddingLeft="10dp"
        android:paddingRight="05dp"
        android:paddingTop="05dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/tv_g_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView6"
        android:layout_below="@+id/textView35"
        android:layout_toEndOf="@+id/imageView6"
        android:layout_toRightOf="@+id/imageView6"
        android:gravity="center"
        android:text="889845412" />
</RelativeLayout>

When you create the recyclerview, you normally have the layout for the individual items in the list and then the layout that contains the actual recyclerview.创建回收器视图时,通常具有列表中各个项目的布局,然后是包含实际回收器视图的布局。 The layout for the actual recyclerview might have contain some type of padding or margin which is why it doesn't fill up the screen.实际 recyclerview 的布局可能包含某种类型的填充或边距,这就是它不会填满屏幕的原因。

You will need to check that layout and not the layout for the individual items in the list.您将需要检查该布局,而不是列表中各个项目的布局。

You have also not posted the layout that contains the recyclerview so we are not able to evaluate.您还没有发布包含 recyclerview 的布局,因此我们无法评估。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM