简体   繁体   English

如何使用SeekBar的进度调整TextView的大小(Android)

[英]How to resize TextView with SeekBar's progress (Android)

I'm triying to change the text size of a TextView using a SeekBar, and it's works fine ONLY when i increase the size, when decrease, the "text size" changes well, but the "textview's layout" seems to have the biggest height you put (The text appears in the center of the layout as if has the match_parent property instead of wrap_content). 我正在尝试使用SeekBar更改TextView的文本大小,并且只有当我增加大小,减小大小时,“文本大小”才能很好地改变,但是“ textview的布局”似乎具有最大的高度,放置(文本显示在布局的中心,就好像具有match_parent属性而不是wrap_content一样)。

I tried many combinations of the textview's layout properties (It's in a RelativeLayout) (H:WRAP_CONT,W:WRAP_CONT / H:MATCH_PAR,W:MATCH_PAR,ALING PARENT TOP TRUE /.....) 我尝试了textview的布局属性的许多组合(位于RelativeLayout中)(H:WRAP_CONT,W:WRAP_CONT / H:MATCH_PAR,W:MATCH_PAR,ALING PARENT TOP TRUE / .....)

Can someone help me?? 有人能帮我吗??

EDIT: The textview should appear on top 编辑:textview应该出现在顶部

LAYOUT 布局

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <RelativeLayout
            android:id="@+id/preview_preview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <ImageView
                android:id="@+id/preview_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent" android:background="@drawable/cuadros_001"/>

            <TextView
                android:id="@+id/preview_text_top"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="TextView" 
                android:textColor="#FFFFFF"/>

            <TextView
                android:id="@+id/preview_text_bottom"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2.5dp"
                android:gravity="bottom|center"
                android:text="PREVIEW_TEXT_BOTTOM"
                android:textColor="#FFFFFF"
                android:textSize="25dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"/>

           </RelativeLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <GridView
            android:id="@+id/preview_gridview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/backgroundtransparencia"
            android:gravity="center"
            android:horizontalSpacing="5dp"
            android:numColumns="3"
            android:stretchMode="columnWidth"
            android:verticalSpacing="10dp" >

        </GridView>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/preview_child_2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>

</ViewFlipper>

---SEEKBAR-- --- SEEKBAR--

seekbar_toptext =(SeekBar)findViewById(R.id.seekbar_toptext);
    seekbar_toptext.setProgress(40);
    seekbar_toptext.incrementProgressBy(05);
    seekbar_toptext.setMax(100);

    seekbar_toptext.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        int topsize;

        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub


        }


        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }

        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {

            preview_text_top.setTextSize(TypedValue.COMPLEX_UNIT_SP ,progress);

        }
    });

Thanks in advance. 提前致谢。

Try this Code... 尝试此代码...

I hope this will helps to you... 希望对您有帮助...

final TextView t1=new TextView(this); 
t1.setText("Hello Android");        
    final SeekBar sk=(SeekBar) findViewById(R.id.seekBar1);     
    sk.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {       

    @Override       
    public void onStopTrackingTouch(SeekBar seekBar) {      
        // TODO Auto-generated method stub      
    }       

    @Override       
    public void onStartTrackingTouch(SeekBar seekBar) {     
        // TODO Auto-generated method stub      
    }       

    @Override       
    public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {     
        // TODO Auto-generated method stub      

        t1.setTextSize(progress);
        Toast.makeText(getApplicationContext(), String.valueOf(progress),Toast.LENGTH_LONG).show();

    }       
});             

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM