`
dawuafang
  • 浏览: 1192022 次
文章分类
社区版块
存档分类
最新评论

记录1

 
阅读更多
android:lineSpacingExtra="10dp"2种方法可以设置TextView文字居中:

一:在xml文件设置: android:gravity="center"

二:在程序中设置: txtTitle.setGravity(Gravity.CENTER);

设置控件居中:

android:layout_gravity="center"是 对textview控件在整个布局中居中,也可以在其父layout中调用设置 android:gravity="center"

程序中也是需要设置其所在控件的父layout,例如:

RelativeLayout.LayoutParams layoutParams=
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
            mTextView.setLayoutParams(layoutParams);

edittext 高度随文字的增加高度自动增加

iProfileEdit.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                changeEditTextHeight(s.toString());
            }
        });



_______________________________________________________________________________________________________________


    private void changeEditTextHeight(String s) {
        TextView textView = new TextView(PostIssueActivity.this);
        textView.setText(s.toString());
        int widthMeasureSpec = MeasureSpec.makeMeasureSpec(iProfileEdit.getMeasuredWidth(), MeasureSpec.EXACTLY);
        int heightMeasureSpec = MeasureSpec.makeMeasureSpec(800, MeasureSpec.AT_MOST);
        textView.measure(widthMeasureSpec, heightMeasureSpec);
        int textHeight = textView.getMeasuredHeight();
        int minHeight = dip2px(80);
        LayoutParams layoutParams = iProfileEdit.getLayoutParams();
        if (textHeight < minHeight) {
            layoutParams.height = minHeight;
        } else {
            layoutParams.height = textHeight;
        }
        iProfileEdit.setLayoutParams(layoutParams);
    }
<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics