Control the listview width and height in Android

Source: Internet
Author: User

============ Problem Description ============


To listveiw fill the item layout is Wrap_content,listview itself also uses wrap_content, but the actual display effect ListView width is full screen, seek solution
Item Layout:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "wrap_content "Android:layout_height=" wrap_content "><textview android:id=" @+id/video_name "android:layout_width=" WR Ap_content "android:layout_height=" wrap_content "android:textcolor=" #ffffff "/></relativelayout>


ListView Layout:
<relativelayout         android:id= "@+id/video_list_box"           android:layout_width= "Wrap_content"          android:layout_height= "Wrap_content"          android:background= "@drawable/list_bg"         android:layout_ Alignparentright= "true"         android:layout_below= "@id/title_box"         >        < Listview           android:id= "@+id/video_list_view"           android:layout_width= "Wrap_content"    android:layout_height= "Wrap_content"           ></ Listview>   </relativelAyout> 

============ Solution 1============


Layout This kind of thing in a single case fortunately said, once combined, the various layouts are nested in each other is not easy to find the law, need to slowly adjust

You put the whole layout file up and see

============ Solution 2============


You can control the width in the code, first take out the width and height of the screen to set

============ Solution 3============


Reference 5 Floor Augleo1989 's reply:
Main layout:
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"      xmlns:tools= "Http://schemas.android.com/tools"     android:layout_width= "Match_parent"     android:layout_height= "Match_parent"     tools:context= ". Mainactivity "     >    <RelativeLayout          android:id= "@+id/video_list_box"           android:layout_width= "Wrap_content"         android:layout_ height= "Wrap_content"         android:background= "@drawable/list_bg"         android:layout_alignparentright= "true"          >        <ListView          &nbSp; android:id= "@+id/video_list_view"           android: Layout_width= "Wrap_content"           android:layout_height= " Wrap_content "          ></ListView>    </RelativeLayout></RelativeLayout>


Item Layout:
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Wrap_content "android:layout_height=" wrap_content "><textview android:id = "@+id/video_name" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:textColor= "#f Fffff "/></relativelayout>

The effect is to display a list of menus on the right side of the screen, with the LIST_BG consistent with the background image.


You set the width of the ListView to 200DP to set the item value to 100DP to see if you can achieve the effect you want, if not, the description is Android internal mechanism problem

Control the listview width and height in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.