Home  >  Q&A  >  body text

android自定义滑动删除控件时在onmeasure()设置width无效

 @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (!once) {
            viewGroup = (LinearLayout) this.getChildAt(0);
            content = (LinearLayout) viewGroup.getChildAt(0);
            menu = (Button) viewGroup.getChildAt(1);
            LinearLayout.LayoutParams ll = (LinearLayout.LayoutParams) content.getLayoutParams();
            ll.width = screenWidth;
            content.setLayoutParams(ll);
            menuWidth = menu.getMeasuredWidth();
            viewGroup.getLayoutParams().width = screenWidth+menuWidth;
            once = true;
        }
    }

        布局:


    

<com.example.yannis.dianming.widget.HorizontalSwipeListview
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/content"
            android:layout_width="384dp"
            android:layout_height="50dp"
            android:background="@color/white"
            android:orientation="vertical">
            <TextView
                android:id="@+id/homeworkName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingBottom="2dp"
                android:paddingLeft="8dp"
                android:paddingTop="4dp"
                android:text=""
                android:textColor="@color/black"
                android:textSize="16sp"/>
            <TextView
                android:id="@+id/homeworkWeek"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/homeworkName"
                android:paddingLeft="8dp"
                android:text=""
                android:textColor="@color/lightblack"
                android:textSize="14sp"/>
        </LinearLayout>
        <Button
            android:layout_width="70dp"
            android:layout_height="50dp"
            android:id="@+id/delete"
            android:text="删除"
            android:textSize="16sp"
            android:textColor="@color/white"
            android:background="@color/red"/>
    </LinearLayout>
</com.example.yannis.dianming.widget.HorizontalSwipeListview>
大家讲道理大家讲道理2760 days ago1068

reply all(0)I'll reply

No reply
  • Cancelreply