如何使用不同的字体在图像视图上保存文本?

时间:2013-09-26 05:29:26

标签: android text fonts android-gridview

我想在图像视图上使用不同的字体在图像视图上保存文本。一旦用户键入文本。文本应该正确地适合使用不同字体的图像视图。这是我的代码

  public class MainActivity extends Activity {

private SharedPreferences prefs;
private EditText editText;
private Button btn;
private SeekBar seek;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    editText=(EditText)findViewById(R.id.editText1);
    seek=(SeekBar)findViewById(R.id.seekBar1);
    btn=(Button)findViewById(R.id.button1);


    // TODO Auto-generated method stub
    prefs=getSharedPreferences("test", MODE_PRIVATE);
    //prefs=getPreferences(MODE_PRIVATE);
    Editor ed=prefs.edit();
    ed.putFloat("Fontsize",editText.getTextSize());
    ed.putString("text", editText.getText().toString());
    ed.commit();
    Toast.makeText(getBaseContext(), "saved Sucessfully",        Toast.LENGTH_SHORT).show();
float fontsize  =prefs.getFloat("Fontsize", 12);
    seek.setProgress((int)fontsize);
    editText.setText(prefs.getString("text", ""));
    editText.setTextSize(seek.getProgress());
    seek.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
            editText.setTextSize(seek.getProgress());

        }
    });

    btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setContentView(R.layout.grid);

            GridView gridView = (GridView) findViewById(R.id.grid_view);

            // Instance of ImageAdapter Class
            gridView.setAdapter(new ImageAdapter(MainActivity.this));

           gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v,
                int position, long id) {

            // Sending image id to FullScreenActivity
            Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
            // passing array index
            i.putExtra("id", position);
            startActivity(i);
        }
    });


        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

1 个答案:

答案 0 :(得分:0)

将edittext和imageview放在相对布局中。这将与它们重叠。你可以调整marigins / padding。