Rounded rect RectF Android example
RectF, drawRoundRect(),
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
canvas.drawColor(Color.GREEN);
Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.ALPHA_8);
Canvas c = new Canvas(b);
RectF rectF = new RectF();
rectF.set(5,5,150,150);
c.drawRoundRect(rectF, 10, 10, paint);
paint.setColor(Color.RED);
canvas.drawBitmap(b, 10,10, paint);
}
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
StringBuilder, res/raw folder, try catch finaly throws, BufferedReader, InputStream, openRawResource, getResources Android example
MainActivity.java
MainActivity.java
public class MainActivity extends Activity {
TextView txtV;
Context cntx;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtV = (TextView)findViewById(R.id.idLabel);
cntx = this;
try {
StringBuilder strBuilder = myFunction(cntx);
txtV.setText(strBuilder);
} catch (IOException e) {
e.printStackTrace();
}
}
private StringBuilder myFunction(Context context) throws IOException {
final Resources resources = context.getResources();
InputStream inputStream = resources.openRawResource(R.raw.my_file);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder strBuild = new StringBuilder();
try {
String line;
while ((line = reader.readLine()) != null) {
strBuild.append(line);
}
} finally {
reader.close();
}
return strBuild;
}
}
private SensorManager mSensorManager;
private PowerManager mPowerManager;
private WindowManager mWindowManager;
private Display mDisplay;
// onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get an instance of the SensorManager
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
// Get an instance of the PowerManager
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
// Get an instance of the WindowManager
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay();
setContentView(R.layout.main); // main.xml or your xml file name
}
Put your sglite database to Android Eclipse project folder named Assets.
On device will copy database file to application folder as this example:
On device will copy database file to application folder as this example:
public void createDatabase(Context myContext) throws IOException {
String sPackName = myContext.getPackageName();
InputStream assetsDB = myContext.getAssets().open("myDatabase");
OutputStream dbOut = new FileOutputStream("/data/data/"+sPackName+"/database");
byte[] buffer = new byte[1024];
int length;
while ((length = assetsDB.read(buffer))>0){
dbOut.write(buffer, 0, length);
}
dbOut.flush();
dbOut.close();
assetsDB.close();
}
RelativeLayout like parent, child Srollview is centered horizontal.
Second RelativeLayout in SrollView have gravity center, every child will centered horizontally and vertically.
Second RelativeLayout in SrollView have gravity center, every child will centered horizontally and vertically.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:gravity="center_horizontal">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView2" >
<RelativeLayout
android:layout_width="320dp"
android:layout_height="wrap_content"
android:background="#e6f825"
android:gravity="center">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Editace: 2011-11-13 20:49:14
Počet článků v kategorii: 396
Url:rounded-rect-rectf-android-example