2014-03-26 169 views
0

我正在開發一個健身應用程序。我的應用程序將有不同的練習,如Push Ups仰臥起坐。每個練習都需要有一個圖像展示給用戶。 我一直在想什麼是解決這個問題的好方法。但我不認爲我的解決方案是好的。你有沒有使用Android上的圖像來顯示圖像?給我你的解決方案,你是如何做到的。顯示圖像Android

鍛鍊有名字,但也有圖像。目的是顯示圖像和練習名稱的特定練習。

我的運動課程現在看起來像這樣: 我想過要保存圖片的路徑,當我需要顯示圖片時我可以訪問它。我正在上傳資產文件夾中的圖像。

public class Exercise { 
    private String exerciseName; 
    private String exerciseSmallImagePath; 
    private String exerciseLargeImagePath; 

public Exercise(String exerciseName, String exerciseSmallImagePath, String exerciseLargeImagePath){ 
    this.exerciseName = exerciseName; 
    this.exerciseSmallImagePath = exerciseSmallImagePath; 
    this.exerciseLargeImagePath = exerciseLargeImagePath; 
    } 
} 
+1

基於所述excersice的名稱創建一個活動和更改[ImageView的](http://developer.android.com/reference/android/widget/ImageView.html)的形象。 我建議只將圖像添加到資源文件夾,以便您可以按照您的方式訪問它們。 –

+0

那麼你是否面臨目前實施的任何問題? – r4jiv007

+1

'你有沒有在Android上使用圖像來顯示圖像?'這讓我感到很開心:D //你對圖像有什麼問題? – Droidman

回答

1

保存圖像源的路徑是一個很好的方法。看看ImageViews爲了顯示您的圖像。存在實現這種ImageView的兩種方法:

1:

<ImageView 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:contentDescription="Some description" /> 

2:之後在OnCreate中-方法在XML定義它,並設置圖像源在Activity編程定義的ImageView :

ImageView imageView = new ImageView(this); 
LinearLayout.LayoutParams vp = 
    new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
        LayoutParams.WRAP_CONTENT); 
imageView.setLayoutParams(vp);   
imageView.setImageResource(fetch your ID here);   
someLinearLayout.addView(imageView); 
1

我想你很熟悉如何在Android中創建簡單的應用程序?如果不是,那麼你應該開始使用樣品,並閱讀Android developers guide

This article可以給你如何使用圖像的良好開端。

至於你應該如何做到這一點,我只能提出一種方法,其餘的則取決於你的想象力。 從創建一個fragment開始,該圖像下面有一個圖像和一個文本(如果您喜歡,還可以在上面)。然後你可以把這個片段放在你想要的新圖像和文字上。 這裏是一個粗略的想法

<LinearLayout (vertical orientation> 
<Image ... /> 
<Text ... /> 
</LinearLayout> 

一旦佈局的地方,你可以在運行時設置的圖像源。

顯示此信息的好方法是讓用戶可以使用滑動操作來導航(view pager)。

每一頁都可以有上面提到的片段,它會顯示一個步驟。這將導致更清晰的幻燈片屏幕樣式指南。