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

时间:2012-07-07 14:16:34

标签: android resize textview seekbar

我正在尝试使用SeekBar更改TextView的文本大小,只有当我增加大小时,它才能正常工作,当减小时,“文本大小”改变很好,但“textview的布局”似乎有您放置的最大高度(文本显示在布局的中心,好像有match_parent属性而不是wrap_content)。

我尝试了很多textview的布局属性组合(它在RelativeLayout中) (H:WRAP_CONT,W:WRAP_CONT / H:MATCH_PAR,W:MATCH_PAR,ALING PARENT TOP TRUE /.....)

有人能帮帮我吗?

编辑: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_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);

        }
    });

提前致谢。

1 个答案:

答案 0 :(得分:0)

试试此代码......

我希望这会对你有所帮助......

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();

    }       
});