Reputation: 136141
I'm developing a test app to gain some confidence with Android Studio. I have created a single-activity app with a countdown timer and a PNG image of a toothbrush.
package com.ecam.myapplication2;
import android.graphics.Color;
import android.os.CountDownTimer;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView mTextField = (TextView)findViewById(R.id.timeRemainingText);
final ProgressBar pBar = (ProgressBar)findViewById(R.id.progressBar);
final ProgressBar pBar2 = (ProgressBar)findViewById(R.id.progressBar2);
final ImageView toothbrushImage = (ImageView)findViewById(R.id.imageView);
final long maxTime = 2 * 6 * 1000;
final long steps = 10;
new CountDownTimer(maxTime, steps) {
public void onTick(long millisUntilFinished) {
long minutesRemaining = millisUntilFinished / 1000 / 60;
long secondsRemaining = (millisUntilFinished / 1000) % 60;
long centisecondsRemaining = (millisUntilFinished / 10) % 100;
float percentCompleted = 100 - (((float)millisUntilFinished) / maxTime) * 100;
//float msFloat = (float) millisUntilFinished;
//int progress = (int)(msFloat/maxTime*100);
//mTextField.setText(progress+"seconds remaining: " + String.format("%.2f", msFloat / 1000));
mTextField.setText(String.format("%02d:%02d.%02d", minutesRemaining, secondsRemaining, centisecondsRemaining));
pBar.setProgress((int)percentCompleted);
pBar2.setProgress(100-(int)percentCompleted);
}
public void onFinish() {
mTextField.setText("done!");
pBar.setProgress(100);
pBar2.setProgress(0);
}
}.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/time_remaining_title"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:textColor="#ff5611ff"
android:textSize="45dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/empty"
android:id="@+id/timeRemainingText"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:gravity="center_horizontal" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="308dp"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:max="100"
android:indeterminate="false" />
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="308dp"
android:layout_height="wrap_content"
android:id="@+id/progressBar2"
android:max="100"
android:indeterminate="false"/>
<ImageView
android:layout_width="308dp"
android:layout_height="50dp"
android:id="@+id/imageView"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:scaleType="fitXY"
android:src="@drawable/toothbrush"
android:adjustViewBounds="true" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
And it is well displayed both on the IDE and on an emulator:
But it does not appear on my device (Nexus 5):
Any idea whys the image is not copied or displayed on my device?
adjustViewBounds=true
Upvotes: 0
Views: 554
Reputation: 403
Try using a smaller size of your image, I had the exact same problem and it worked for me.
Upvotes: 1