卓listpopupwindow列表项的TextView不是多行

卓listpopupwindow列表项的TextView不是多行

本文介绍了安卓listpopupwindow列表项的TextView不是多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ListPopupWindow 自定义列表项的布局。但项目的TextView 是不是被多行。我该怎么做?

 最后ListPopupWindow showRoomListPopupWindow =新ListPopupWindow(
                getActivity());
        showRoomListPopupWindow.setAdapter(新ArrayAdapter(
                getActivity(),
                R.layout.movi​​e_detail_spinner_item,movieShowRoomARList));
        showRoomListPopupWindow.setModal(真);
// showRoomListPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
        showRoomListPopupWindow.setAnchorView(tvProgramSeansClick_TXT);

XML布局:

 <?XML版本=1.0编码=UTF-8&GT?;
<的TextView
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =FILL_PARENT
        机器人:填充=10dp
        机器人:文字样式=大胆
        安卓的minlines =3
        机器人:单线=假
        />


解决方案

我试图重新您的情况,我已经成功地得到您的code工作,只是做以下内容:

我AnchorView是按钮,在 RelativeLayout的,就像这样:

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
  <按钮
    机器人:ID =@ + ID /弹出
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_centerHorizo​​ntal =真
    机器人:layout_centerVertical =真
    机器人:背景=@空
    机器人:知名度=隐形
    机器人:文字=弹出
    机器人:textAppearance =@安卓ATTR / textAppearanceSmall/>

然后,我有我的活动里面以下code 的onCreate()

 按钮弹出式按钮=(按钮)findViewById(R.id.popup);    ArrayList的<串GT;阵列=新的ArrayList<串GT;();
    array.add(spendisse VEL自由人lacinia预期值,也hendrerit posuere NEC交流SEM。Aliquam laoreet ullamcorper tortor,tincidunt suscipit爱神枕格言。评级机构eleifend赌注在laoreet facilisis。射精sociis natoque penatibus等magnis DIS临产蒙特斯,nascetur ridic Lorem存有) ;
    array.add(奥迪奥。Quisque在rutrum得力士。Nullam hendrerit nisl非ligula condimentum杂色山雀aliquet eget turpis。评级机构的cursus arcu ornare ELIT格言,等aliquet SEM condimentum。Praesent mauris英里,malesuada volutpat名言一,肝门非mauris。评级机构非SCE);
    array.add(预期值,也普罗quisquam EST魁dolorem存有quia悲坐阿梅德,consectetur,adipisci王梦奎);
    array.add(ltricies interdum坐阿梅德NEC赌注。Suspendisse VEL悲悲。Donec eget马蒂斯LOREM。Donec eget华富PORTA,hendrerit SAPIEN一,interdum arcu整型rutrum,事前的sed posuere adipiscing,nisl英里malesuada LOREM,QUIS egestas SEM augue福奇);    最后ListPopupWindow showRoomListPopupWindow =新ListPopupWindow(SecondActivity.this);
    showRoomListPopupWindow.setAdapter(新ArrayAdapter(SecondActivity.this,
            R.layout.movi​​e_detail_spinner_item,数组));
    showRoomListPopupWindow.setModal(真);    showRoomListPopupWindow.setAnchorView(弹出式按钮);    showRoomListPopupWindow.setWidth(ListPopupWindow.WRAP_CONTENT);    showRoomListPopupWindow.setOnItemClickListener(新OnItemClickListener(){        @覆盖
        公共无效onItemClick(适配器视图<>母公司,观景,INT位置,长的id){
            Toast.makeText(SecondActivity.this,单击项目+位置,Toast.LENGTH_SHORT).show();
        }
    });    popupButton.post(新的Runnable(){
        公共无效的run(){
            showRoomListPopupWindow.show();
        }
    });

请注意,我所有的字符串是很长,我的按钮有其可见性设置为不可见,不走了。

这是我所得到的:

正如你所看到,文本具有一个最小的3线和物品的宽度是确定的。

我希望能帮助你。

让我知道,如果它的工作适合你。

I am using ListPopupWindow with custom list item layout. But list item TextView isn't being multi-line. How can I do that?

final ListPopupWindow showRoomListPopupWindow = new ListPopupWindow(
                getActivity());
        showRoomListPopupWindow.setAdapter(new ArrayAdapter(
                getActivity(),
                R.layout.movie_detail_spinner_item, movieShowRoomARList));
        showRoomListPopupWindow.setModal(true);
//        showRoomListPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);


        showRoomListPopupWindow.setAnchorView(tvProgramSeansClick_TXT);

XML layout:

<?xml version="1.0" encoding="utf-8"?>
<TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:padding="10dp"
        android:textStyle="bold"
        android:minLines="3"
        android:singleLine="false"
        />
解决方案

I tried to recreate your case, and I've managed to get your code working, just doing the following:

My AnchorView is a Button, inside a RelativeLayout, like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
  <Button
    android:id="@+id/popup"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:background="@null"
    android:visibility="invisible"
    android:text="Popup"
    android:textAppearance="@android:attr/textAppearanceSmall" />

Then, I have the following code inside my Activity onCreate():

Button popupButton = (Button) findViewById(R.id.popup);

    ArrayList<String> array = new ArrayList<String>();
    array.add("spendisse vel libero lacinia neque hendrerit posuere nec ac sem. Aliquam laoreet ullamcorper tortor, tincidunt suscipit eros pulvinar dictum. Cras eleifend ante at laoreet facilisis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridic lorem ipsum");
    array.add("Odio. Quisque at rutrum tellus. Nullam hendrerit nisl non ligula condimentum varius aliquet eget turpis. Cras cursus arcu ornare elit dictum, et aliquet sem condimentum. Praesent mauris mi, malesuada volutpat dictum a, porta non mauris. Cras non sce");
    array.add("Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci veli");
    array.add("ltricies interdum sit amet nec ante. Suspendisse vel dolor dolor. Donec eget mattis lorem. Donec eget quam porta, hendrerit sapien a, interdum arcu. Integer rutrum, ante sed posuere adipiscing, nisl mi malesuada lorem, quis egestas sem augue fauci");

    final ListPopupWindow showRoomListPopupWindow = new ListPopupWindow(SecondActivity.this);
    showRoomListPopupWindow.setAdapter(new ArrayAdapter(SecondActivity.this,
            R.layout.movie_detail_spinner_item, array));
    showRoomListPopupWindow.setModal(true);

    showRoomListPopupWindow.setAnchorView(popupButton);

    showRoomListPopupWindow.setWidth(ListPopupWindow.WRAP_CONTENT);

    showRoomListPopupWindow.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(SecondActivity.this, "Clicked item " + position, Toast.LENGTH_SHORT).show();
        }
    });

    popupButton.post(new Runnable() {
        public void run() {
            showRoomListPopupWindow.show();
        }
    });

Note that all my strings are very long, and my Button has its visibility set to INVISIBLE, not GONE.

And this is what I get:

As you can see, the text has a minimum 3 lines and the width of the items is ok.

I hope to have helped you.

Let me know if it worked for you.

这篇关于安卓listpopupwindow列表项的TextView不是多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 17:38