2016-09-29 61 views
1

我一直在嘗試並試圖在昨天整天將我的徽標圖像插入到我的應用程序中。但沒有運氣。 我正在使用ImageView,並且正在應用來自Internet的所有建議,並且我已經構建了超過50個APK來測試它,並且每次都是失敗。將徽標圖像插入到應用程序

我的圖像是在drawable-nodpi,drawable-xdpi,drawable-xxdpi,drawable-xxxdpi和mipmap等中。 此外,我嘗試過不同格式的圖像和尺寸。我的最後一幅圖像是300x408px 在Android Studio圖像上顯示,但不顯示任何設備或平板電腦。 這裏是源代碼

文件main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:weightSum="0"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:srcCompat="@drawable/logo" 
    android:id="@+id/imageView4" /> 

<Button 
    android:id="@+id/play" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dip" 
    android:text="Pusti" /> 

<Button 
    android:id="@+id/stop" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dip" 
    android:text="Zaustavi" /> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:srcCompat="@mipmap/tower" 
    android:id="@+id/imageView3" /> 

文件MusicAndroidActivity.java

package clever.radio; 

import java.io.IOException; 

import android.app.Activity; 
import android.graphics.BitmapFactory; 
import android.media.AudioManager; 
import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.webkit.WebView; 
import android.widget.Button; 
import android.widget.Toast; 

import static android.R.attr.id; 

public class MusicAndroidActivity extends Activity { 

    static MediaPlayer mPlayer; 
    Button buttonPlay; 
    Button buttonStop; 
    String url = "http://radioclever.stream:8000/stream"; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     buttonPlay = (Button) findViewById(R.id.play); 
     buttonPlay.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 
       mPlayer = new MediaPlayer(); 
       mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
       try { 
        mPlayer.setDataSource(url); 
       } catch (IllegalArgumentException e) { 
        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show(); 
       } catch (SecurityException e) { 
        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show(); 
       } catch (IllegalStateException e) { 
        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       try { 
        mPlayer.prepare(); 
       } catch (IllegalStateException e) { 
        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show(); 
       } catch (IOException e) { 
        Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show(); 
       } 
       mPlayer.start(); 
      } 
     }); 

     buttonStop = (Button) findViewById(R.id.stop); 
     buttonStop.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       if(mPlayer!=null && mPlayer.isPlaying()){ 
        mPlayer.stop(); 
       } 
      } 
     }); 
    } 

    protected void onDestroy() { 
     super.onDestroy(); 
     // TODO Auto-generated method stub 
     if (mPlayer != null) { 
      mPlayer.release(); 
      mPlayer = null; 
     } 
    } 
} 

文件的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="clever.radio" 
android:versionCode="1" 
android:versionName="1.1" > 

<uses-sdk 
    android:minSdkVersion="9" 
    android:targetSdkVersion="15" /> 

<uses-permission android:name="android.permission.INTERNET" /> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".MusicAndroidActivity" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

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

的strings.xml

<resources> 
    <string name="app_name">Radio Clever</string> 
</resources> 

dimens.xml

+0

任何錯誤日誌@Luka? –

+0

必須嘗試將圖像放在可繪製的文件夾中? – AbhayBohra

+0

發佈你的活動代碼以及 –

回答

1

嘗試android:src ins登錄app:srcCompat

0

請檢查findViewById的ImageView的。

沒有它,你沒有得到Imageview。

+0

錯誤的標記,對不起,我通過@Akash回答很有用,android:src完美無缺地進行了編輯。謝謝反正可能會幫助別人來這裏 –

+0

請不要評論告訴別人投票。也只能使用代碼塊代碼 –

+1

ok @ cricket_007 –