android(试图为手机和标签使用hdpi图像)但不工作

时间:2016-02-19 11:57:42

标签: android

我在使用(xxxhdpi)标签时尝试在android中进行启动画面,但是当我在手机中使用它时,图像只是伸出来所以请帮帮我

3 个答案:

答案 0 :(得分:1)

这里有很多东西。首先,为什么你只想保留你正在谈论的图像的一个副本?

拥有所有相应密度的图像总是更好,否则android会对图像进行缩小和放大。 如果担心apk尺寸,您可以查看密度分割。

现在,回到您的问题,它取决于您的imageview的scaleType。你可以做这样的事情(如果你不关心图像的尺寸,否则你可以将scaleType设置为fitXY):

<ImageView
  ...
  android:scaleType="centerCrop"
  ...
</ImageView>

现在将图像加载到您的imageview中,我会建议您使用Picasso库。 在您的活动中,您可以执行以下操作:

onCreate(...){
  ...
  Picasso.with(mContext).load(R.drawable.my_splash_image).into(mMyImageView);
  ...
}

如果这清楚了你的怀疑,请告诉我。

答案 1 :(得分:0)

要解决图像拉伸问题,请尝试:

<ImageView android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:scaleType="centerCrop"
           android:adjustViewBounds="true"/>

另外,我建议你阅读Supporting Multiple Screens

答案 2 :(得分:0)

尝试将此活动作为您的启动活动。 1.SplashActivity.java

public class SplashActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    Thread timerThread = new Thread(){
        public void run(){
            try{
                sleep(3000);
            }catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent intent = new Intent(SplashActivity.this,MainActivity.class);
                TextView textView=(TextView)findViewById(R.id.textView1);
                startActivity(intent);
            }
        }
    };
    timerThread.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}}

2.制作这样的布局 splash.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_image"
android:orientation="vertical">

3.确保你显示应该启动app主线程。如下所示 的manifest.xml

        <activity
        android:name="com.example.brahmaiah.demo_proj_filpkart.SplashActivity"
        android:label="@string/app_name"
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

`希望这对你有用。