如何设置TextView的宽度与高度相同并重绘它?

时间:2015-01-31 17:05:14

标签: android expandablelistview

我在expandableListView中的标题行中有notesCounter(TextView)。我想绘制相同的圆圈。 TextView高度设置为match_parent。现在开始我的问题...我想设置椭圆的宽度与高度相同。我测量它,它返回正确的值(高度),我将其设置为TextView,但它没有刷新。我的问题:如何刷新TextView?

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View rowView, ViewGroup parent) {
    Container container = (Container) getGroup(groupPosition);

    if (rowView == null) {
        rowView = inflater.inflate(R.layout.item_container, null);
    }
    TextView containerName = (TextView) rowView.findViewById(R.id.container_name);
    containerName.setText(container.name);

    notesCounter = (TextView) rowView.findViewById(R.id.notes_counter);
    notesCounter.setText(getChildrenCount(groupPosition) + "");

    final TextView nt = notesCounter;
    notesCounter.post(new Runnable() {

        @Override
        public void run() {
            // nt.getHeight() - return 67 - good!
            notesCounter.setWidth(nt.getHeight()); // I WANT REDRAW IT AND SEE EQUAL CIRCLE! 
            //notesCounter will set width after swipe ExpandableListView and "hide and then appear view"
        }
    });

    Util.loadFont(context, containerName, FONT.GothamExtraLight);
    Util.loadFont(context, notesCounter, FONT.GothamExtraLight);

    return rowView;
}

1 个答案:

答案 0 :(得分:0)

见下文:

new Handler().post(new Runnable() {
        @Override
        public void run() {
            notesCounter.setWidth(notesCounter.getHeight());
        }
    });