
我是android的初学者.我想显示一个包含数字的自定义列表视图.我自定义了ListVIEw大小(androID:layout_height =“ 50dp”).但是,当我运行该应用程序时,它会在很大程度上显示未提供的大小.我不知道如何解决这个问题.请任何人帮助我.
activity_topic_List.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout 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:orIEntation="vertical" tools:context="com.example.yuvi.secrectsforhappylife.topicList"> <ListVIEw androID:ID="@+ID/topicList" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" /></linearLayout>Titledesign.xml
<?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="50dp" androID:background="@drawable/storyList"> <TextVIEw androID:ID="@+ID/topicTitle" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_centerHorizontal="true" androID:layout_centerVertical="true" androID:text="@string/Title" androID:textSize="12pt" androID:textStyle="bold" androID:textcolor="@androID:color/background_light" /></relativeLayout>topicList.java
public class topicList extends AppCompatActivity { String topic[]={"one","two","three","four","five","six","seven","eight","nine","ten"}; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_topic_List); ListVIEw ListVIEw=(ListVIEw)findVIEwByID(R.ID.topicList); CustomAdapter customAdapter=new CustomAdapter(); ListVIEw.setAdapter(customAdapter); } class CustomAdapter extends BaseAdapter { @OverrIDe public int getCount() { return topic.length; } @OverrIDe public Object getItem(int position) { return null; } @OverrIDe public long getItemID(int position) { return 0; } @OverrIDe public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) { convertVIEw=getLayoutInflater().inflate(R.layout.Titledesign,null); TextVIEw Title=(TextVIEw)convertVIEw.findVIEwByID(R.ID.topicTitle); Title.setText(topic[position]); return convertVIEw; } }}解决方法:
I want to fix the List cell height
FYI
您要为每个单元格添加高度
然后
<?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" androID:background="@drawable/storyList"> <TextVIEw androID:ID="@+ID/topicTitle" androID:layout_wIDth="wrap_content" androID:layout_height="50dp" androID:layout_centerHorizontal="true" androID:layout_centerVertical="true" androID:text="@string/Title" androID:textSize="12sp" androID:textStyle="bold" androID:textcolor="@androID:color/background_light" /></relativeLayout>注意
使用TextVIEw Size单位sp代替pt.
总结以上是内存溢出为你收集整理的如何在Android中自定义ListView的高度?全部内容,希望文章能够帮你解决如何在Android中自定义ListView的高度?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)