Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android设置listview项';它的高度是所有孩子中最高的,所以看起来像一张有边框的桌子_Android_Android Layout_Android Listview_Tableview_Android Adapter - Fatal编程技术网

android设置listview项';它的高度是所有孩子中最高的,所以看起来像一张有边框的桌子

android设置listview项';它的高度是所有孩子中最高的,所以看起来像一张有边框的桌子,android,android-layout,android-listview,tableview,android-adapter,Android,Android Layout,Android Listview,Tableview,Android Adapter,我试图在Listview和Adapter的帮助下显示动态TableView。我正在为边界设置可绘制的形状 从逻辑上讲,我试图获得行中所有子视图的最高高度,然后将该高度设置为所有子视图 为此,我使用了addOnGlobalLayoutListener,但它只调用了一次。 让我知道我如何才能达到表 我想实现这一目标,但正如你们所看到的,边界并不明显。提及 将Listview与适配器一起使用 @Override public View g

我试图在Listview和Adapter的帮助下显示动态TableView。我正在为边界设置可绘制的形状

从逻辑上讲,我试图获得行中所有子视图的最高高度,然后将该高度设置为所有子视图

为此,我使用了addOnGlobalLayoutListener,但它只调用了一次。 让我知道我如何才能达到表

我想实现这一目标,但正如你们所看到的,边界并不明显。提及

将Listview与适配器一起使用

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                final viewHoler holder;
                if (convertView == null) {  // if it's not recycled, initialize some attributes
                    convertView =    inflater.inflate(R.layout.inflateordertakingproductview, null);
                    holder = new viewHoler();
                    holder.tvproductName=(TextView)convertView.findViewById(R.id.tvitem);
                    holder.tvprice=(TextView)convertView.findViewById(R.id.tvprice);
                    holder.edqty=(EditText)convertView.findViewById(R.id.edqty);
                    holder.edfree=(EditText)convertView.findViewById(R.id.edfree);
                    convertView.setTag(holder);
                } else {
                    holder=(viewHoler)convertView.getTag();
                }
                ViewTreeObserver vto = holder.tvproductName.getViewTreeObserver();
                vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                    @Override
                    public void onGlobalLayout() {
                        int height=0;

                        Log.v("Name Height",""+holder.tvproductName.getHeight());
                        Log.v("Price Height",""+holder.tvprice.getHeight());
                        Log.v("Edqty Height",""+holder.edqty.getHeight());
                        Log.v("Edfree Height",""+holder.edfree .getHeight());
                        android.view.ViewGroup.LayoutParams  _lP=holder.tvproductName.getLayoutParams();
                        _lP.height=LayoutParams.WRAP_CONTENT;
                        holder.tvproductName.setLayoutParams(_lP);
                        holder.tvproductName.requestLayout();

                        _lP=holder.tvprice.getLayoutParams();
                        _lP.height=LayoutParams.WRAP_CONTENT;
                        holder.tvprice.setLayoutParams(_lP);
                        holder.tvprice.requestLayout();

                        _lP=holder.edqty.getLayoutParams();
                        _lP.height=LayoutParams.WRAP_CONTENT;
                        holder.edqty.setLayoutParams(_lP);
                        holder.edqty.requestLayout();

                        _lP=holder.edfree .getLayoutParams();
                        _lP.height=LayoutParams.WRAP_CONTENT;
                        holder.edfree.setLayoutParams(_lP);
                        holder.edfree.requestLayout();
                        if(holder.tvproductName.getHeight()>height){
                            height=holder.tvproductName.getHeight();
                        }
                        if(holder.tvprice.getHeight()>height){
                            height=holder.tvprice.getHeight();
                        }
                        if(holder.edqty.getHeight()>height){
                            height=holder.edqty.getHeight();
                        }
                        if(holder.edfree .getHeight()>height){
                            height=holder.edfree .getHeight();
                        }
                        Log.v("MAX Height",""+height);
                        _lP=holder.tvproductName.getLayoutParams();
                        _lP.height=height;
                        holder.tvproductName.setLayoutParams(_lP);
                        holder.tvproductName.setGravity(Gravity.LEFT);

                        _lP=holder.tvprice.getLayoutParams();
                        _lP.height=height;
                        holder.tvprice.setLayoutParams(_lP);
                        holder.tvprice.setGravity(Gravity.RIGHT);
                        _lP=holder.edqty.getLayoutParams();
                        _lP.height=height;
                        holder.edqty.setLayoutParams(_lP);
                        holder.edqty.setGravity(Gravity.RIGHT);
                        _lP=holder.edfree .getLayoutParams();
                        _lP.height=height;
                        holder.edfree .setLayoutParams(_lP);
                        holder.edfree .setGravity(Gravity.RIGHT);
                        holder.tvproductName.requestLayout();
                        holder.tvprice.requestLayout();
                        holder.edqty.requestLayout();
                        holder.edfree.requestLayout();

                        Log.v("Product Name",holder.tvproductName.getText().toString());
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            holder.tvproductName.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        } else {
                            holder.tvproductName.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                        }
                    }
                });
                hybridProductOffer _hp=_arrlist_product.get(position);
                String _price,_itemcode,_offerid;
                if(_hp.get_offerid()!=null ){
                    _price=_hp.get_offerprice();
                    _offerid=_hp.get_offerid();
                    holder.tvprice.setText( _hp.get_offermrp());
                }else{
                    _price=_hp.get_itemprice();
                    _offerid=null;
                    holder.tvprice.setText(_hp.get_itemprice());
                }
                _itemcode=_hp.get_itemcode();

                holder.tvproductName.setText(_hp.get_itemname());
                return convertView;
            }
线性布局XML:

        <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:baselineAligned="false"
        android:weightSum="1" > 
        <TextView
            android:id="@+id/tvitem"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_weight="0.4"
            android:background="@drawable/tableborderoffwhite"
            android:gravity="left"
            android:paddingBottom="2dp"
            android:paddingLeft="5dp"
            android:paddingRight="2dp"
            android:paddingTop="2dp"
            android:text="Item"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="15sp" /> 
        <TextView
            android:id="@+id/tvprice"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_weight="0.2"
            android:background="@drawable/tableborderoffwhite"
            android:gravity="right"
            android:paddingBottom="2dp"
            android:paddingLeft="2dp"
            android:paddingRight="5dp"
            android:paddingTop="2dp"
            android:text="Price"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="15sp" /> 
        <EditText
            android:id="@+id/edqty"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_weight="0.2"
            android:background="@drawable/tableborderoffwhite"
            android:gravity="right"
            android:paddingBottom="2dp"
            android:paddingLeft="2dp"
            android:paddingRight="5dp"
            android:paddingTop="2dp"
            android:text="0"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="15sp" /> 
        <EditText
            android:id="@+id/edfree"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_weight="0.2"
            android:background="@drawable/tableborderoffwhite"
            android:gravity="right"
            android:paddingBottom="2dp"
            android:paddingLeft="2dp"
            android:paddingRight="5dp"
            android:paddingTop="2dp"
            android:text="0"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="15sp" />
    </LinearLayout>


提前感谢,感谢您的帮助

据我所知,您希望listview行具有不同的高度(取决于布局中最高子级的高度),并对所有子级实现相同的高度


你为什么不把孩子的身高定为“匹配父母”?那你就不需要考虑孩子的身高了。然后您可以将父版面的高度设置为“包裹内容”,这样每个版面都将具有最高子版面的高度。

非常感谢。你救了我去自定义视图和所有这些。