layout-sw600dp values-sw600dp Android example of use
Why the app selects data from basic layout folder if smallest width is higher then the number in folder name?
Example 1
layout-sw600dp values-sw600dp (smallest width sw for data usage from this folder is 600dp density independent pixel!!!!!)
Device screen resolution is 1200 x 900 px (pixel) Wow, app to be select data from sw600dp folder! Realy?
DPI of device screen - dot per inch (pixel per inch) is 480 pixel it is wery important number!
In our case smallest dimension of screen must be at least 1800 real - physical pixels (1800 px / 3 ratio(dpi/160) = 600 dp (dip density independend pixels) to be used data from folders values-sw600dp and layout-sw600dp.
Example 2 see Example 1 abouve
Device: Nexus 7 (2012) selected from Android Studio tool layout editor
Resolution: 800x1280 px
DPI: tvdpi (approximately 213dpi)
Ratio: 1.33 (213 / 160)
Smallest width in px: 800
Convert px to dp: 601.5 (800 / 1.33)
Result:Smallest width is 601.5dp The App to be used data from folders values-sw600dp and layout-sw600dp.
Example 1
layout-sw600dp values-sw600dp (smallest width sw for data usage from this folder is 600dp density independent pixel!!!!!)
Device screen resolution is 1200 x 900 px (pixel) Wow, app to be select data from sw600dp folder! Realy?
DPI of device screen - dot per inch (pixel per inch) is 480 pixel it is wery important number!
- App selects smallest dimension of screen. In our case 900 px
Medium screen have 160 dpi (The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen.). - App calculate ratio 480 / 160 = 3 (The conversion of dp units to screen pixels: px = dp * (dpi / 160))
- App calculate smallest dimesnion of screen in dp 900 / 3 = 300 dip or dp (density independed pixel).
- App selects data from basic values and layout folder because sw600dp is greater than 300dp.
In our case smallest dimension of screen must be at least 1800 real - physical pixels (1800 px / 3 ratio(dpi/160) = 600 dp (dip density independend pixels) to be used data from folders values-sw600dp and layout-sw600dp.
Example 2 see Example 1 abouve
Device: Nexus 7 (2012) selected from Android Studio tool layout editor
Resolution: 800x1280 px
DPI: tvdpi (approximately 213dpi)
Ratio: 1.33 (213 / 160)
Smallest width in px: 800
Convert px to dp: 601.5 (800 / 1.33)
Result:Smallest width is 601.5dp The App to be used data from folders values-sw600dp and layout-sw600dp.
396LW NO topic_id
AD
Další témata ....(Topics)
R.string.app_name to String example.
MyActivity.java
res/values/string.xml
MyActivity.java
Resources res = getResources();
String sText = res.getString(R.string.app_name);
res/values/string.xml
<resources>
<string name="app_name">My app name</string>
</resources>
Wiktionary - SDK samples Android
about.xml
protected void showAbout() {
// Inflate the about message contents
View messageView = getLayoutInflater().inflate(R.layout.about, null, false);
// When linking text, force to always use default color. This works
// around a pressed color state bug.
TextView textView = (TextView) messageView.findViewById(R.id.about_credits);
int defaultColor = textView.getTextColors().getDefaultColor();
textView.setTextColor(defaultColor);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.app_icon);
builder.setTitle(R.string.app_name);
builder.setView(messageView);
builder.create();
builder.show();
}
about.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project
//www.apache.org/licenses/LICENSE-2.0
-->
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dip">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/app_descrip"
android:textColor="?android:attr/textColorPrimaryInverse" />
<TextView
android:id="@+id/about_credits"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dip"
android:textSize="16sp"
android:text="@string/app_credits"
android:autoLink="web"
android:textColor="?android:attr/textColorPrimaryInverse" />
</LinearLayout>
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);
}
}
}
Example have error code:
//developer.android.com/training/basics/fragments/creating.html
Try to change ArticleFragment.java
//developer.android.com/training/basics/fragments/creating.html
Try to change ArticleFragment.java
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.fragments;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class ArticleFragment extends Fragment {
final static String ARG_POSITION = "position";
int mCurrentPosition = -1;
TextView articleText;
@Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Bundle savedInstanceState) {
//
// // If activity recreated (such as from screen rotate), restore
// // the previous article selection set by onSaveInstanceState().
// // This is primarily necessary when in the two-pane layout.
// if (savedInstanceState != null) {
// mCurrentPosition = savedInstanceState.getInt(ARG_POSITION);
// }
//
// // Inflate the layout for this fragment
// return inflater.inflate(R.layout.article_view, container, false);
// }
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// If activity recreated (such as from screen rotate), restore
// the previous article selection set by onSaveInstanceState().
// This is primarily necessary when in the two-pane layout.
if (savedInstanceState != null) {
mCurrentPosition = savedInstanceState.getInt(ARG_POSITION);
}
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.article_view, container, false);
articleText = (TextView) rootView.findViewById(R.id.article);
return rootView;
}
@Override
public void onStart() {
super.onStart();
// During startup, check if there are arguments passed to the fragment.
// onStart is a good place to do this because the layout has already been
// applied to the fragment at this point so we can safely call the method
// below that sets the article text.
Bundle args = getArguments();
if (args != null) {
// Set article based on argument passed in
updateArticleView(args.getInt(ARG_POSITION));
} else if (mCurrentPosition != -1) {
// Set article based on saved instance state defined during onCreateView
updateArticleView(mCurrentPosition);
}
}
public void updateArticleView(int position) {
//TextView article = (TextView) getActivity().findViewById(R.id.article); //Error: article=null.
if (articleText != null)
articleText.setText(Ipsum.Articles[position]);
mCurrentPosition = position;
}
/* ERROR public void updateArticleView(int position) {
TextView article = (TextView) getActivity().findViewById(R.id.article);
article.setText(Ipsum.Articles[position]);
mCurrentPosition = position;
}*/
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Save the current article selection in case we need to recreate the fragment
outState.putInt(ARG_POSITION, mCurrentPosition);
}
}
do while Java example
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "Hello", "people", "hello", "world!" };
int i = 0;
// first cycle is always executed
do {
System.out.println("Loop: " + i);
System.out.println(arrayOfString[i]);
i++;
}while ( i == -1 );
}
}
/*
Loop: 0
Hello
*/
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "Hello", "people", "hello", "world!" };
int i = 0;
do {
System.out.println("Loop: " + i);
System.out.println(arrayOfString[i]);
i++;
}while ( i < arrayOfString.length );
}
}
/*
Loop: 0
Hello
Loop: 1
people
Loop: 2
hello
Loop: 3
world!
*/
Editace: 2016-03-18 10:52:40
Počet článků v kategorii: 396
Url:layout-sw600dp-values-sw600dp-android-example-of-use