3

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

  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;
}

}

4

1 回答 1

0

将edittext和imageview放在相对布局中。这将使它们重叠。然后您可以调整边距/填充。

于 2013-09-26T05:41:44.010 回答