fragment Binary XML file line Must specify unique android:id, android:tag, or have a parent with an id for
FrameLayou, fragment have to unique id android:id="@+id/your_id_unique"
<FrameLayout xmlns:android="//schemas.android.com/apk/res/android"
xmlns:tools="//schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/your_id_unique"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="cz.okhelp.notepad.AddNoteFragment"
tools:layout="@layout/add_note" />
</FrameLayout>
396LW NO topic_id
AD
Další témata ....(Topics)
public class ApokusActivity 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.YELLOW);
paint.setFilterBitmap(true);
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),R.drawable.flower_blue);
int targetWidth = bitmapOrg.getWidth() * 2;
int targetHeight = bitmapOrg.getHeight() * 2;
Bitmap bmp = Bitmap.createBitmap(targetWidth, targetHeight,Bitmap.Config.ARGB_8888);
RectF rectf = new RectF(0, 0, targetWidth, targetHeight);
Canvas c = new Canvas(bmp);
Path path = new Path();
path.addRect(rectf, Path.Direction.CW);
c.clipPath(path);
c.drawBitmap( bitmapOrg, new Rect(0, 0, bitmapOrg.getWidth(), bitmapOrg.getHeight()),
new Rect(0, 0, targetWidth, targetHeight), paint);
Matrix matrix = new Matrix();
matrix.postScale(1f, 1f);
Bitmap resizedBitmap = Bitmap.createBitmap(bmp, 0, 0, targetWidth, targetHeight, matrix, true);
int h = bitmapOrg.getHeight();
canvas.drawBitmap(bitmapOrg, 10,10, paint);
canvas.drawBitmap(resizedBitmap, 10,10 + h + 10, paint);
}
}
}
If Android emulator freezes at startup, try create new virtual device with smaller memory and cpu usage, or select older version of Android, or buy new pc with higher performance.
- open AVD MANAGER
- press Create Virtual Device
- select Device with small memory usage (e.g. 480x800 of resolution) - Next
- check - Show downloadable ....
- Download - lower version of system Android, select, press - Next
- check data, Show Advanced Settings, check Use host... and press Finish
Call findViewById from onCreateView
res\layout
activity_main.xml
fragment_main.xml
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.containerMoje, new PlaceholderFragment()).commit();
}
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
if (container == null) {
return null;
}
TextView mText;
mText = (TextView)rootView.findViewById(R.id.idText);
mText.setText("Hello from fragment_main");
return rootView;
}
}
}
res\layout
activity_main.xml
<FrameLayout xmlns:android="//schemas.android.com/apk/res/android"
xmlns:tools="//schemas.android.com/tools"
android:id="@+id/containerMoje"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="cz.okhelp.autoskola.MainActivity"
tools:ignore="MergeRootFrame" />
fragment_main.xml
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
xmlns:tools="//schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="cz.okhelp.autoskola.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/idText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
Html.fromHtml(), setText(), textView.setText(Html.fromHtml(String htmlFormat)), Android example.
TextView mIdTextOk = (TextView)findViewById(R.id.idTextOk);
int _nOk = 57;
// number 57 will bold style
mIdTextOk.setText(Html.fromHtml( "OK: "+"<b>"+_nOk+"</b>"));
Editace: 2016-02-19 21:27:08
Počet článků v kategorii: 396
Url:fragment-binary-xml-file-line-must-specify-unique-androidid-androidtag-or-have-a-parent-with-an-id-for