2012-05-16 49 views
0

我是新來的發展,所以我不知道如果我這樣做是正確 我剛剛下載從市場的應用程序,它不適合我的屏幕(LDPI 240×320)在高度上...底部的一些按鈕不會出現。 所以我用Google搜索一些信息,並想盡一切...... 這裏是佈局/ main.xml中Android應用的屏幕尺寸不適合裝置

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"> 
    <LinearLayout android:orientation="vertical" android:id="@id/LLImage" android:layout_width="fill_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:minHeight="100.0dip" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"> 
     <RelativeLayout android:id="@id/drag_layer" android:layout_width="fill_parent" android:layout_height="370.0dip" android:adjustViewBounds="true" android:minHeight="100.0dip"> 
      <ImageView android:id="@id/imageViewContainer" android:layout_width="fill_parent" android:layout_height="370.0dip" android:src="@drawable/backgsammi" android:scaleType="matrix" android:adjustViewBounds="true" android:minHeight="100.0dip" /> 
      <ImageView android:id="@id/imageWatermark" android:visibility="invisible" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/watermark" android:layout_alignParentRight="true" /> 
     </RelativeLayout> 
    </LinearLayout> 
    <LinearLayout android:orientation="vertical" android:id="@id/mainLLauout" android:layout_width="fill_parent" android:layout_height="fill_parent" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"> 
     <LinearLayout android:gravity="center_horizontal" android:orientation="horizontal" android:background="@drawable/background" android:layout_width="fill_parent" android:layout_height="50.0dip" 
      xmlns:android="http://schemas.android.com/apk/res/android"> 
      <ImageButton android:padding="0.0px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3.0dip" android:src="@drawable/open" android:text="Select Picture" android:onClick="openGallery" /> 
      <ImageButton android:padding="0.0px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3.0dip" android:src="@drawable/cat" android:text="Choose Cat" android:onClick="chooseCat" /> 
      <ImageButton android:id="@id/btnFlip" android:padding="0.0px" android:longClickable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3.0dip" android:src="@drawable/rotate" android:onClick="rotateImage" /> 
      <ImageButton android:padding="0.0px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3.0dip" android:src="@drawable/eraser" android:onClick="eraseImage" /> 
      <ImageButton android:id="@id/btnSave" android:padding="0.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3.0dip" android:src="@drawable/save" android:text="Save" android:onClick="saveToGallery" /> 
      <ImageButton android:padding="0.0dip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="3.0dip" android:src="@drawable/help" android:text="Save" android:onClick="openHelp" /> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

我想這是因爲「機器人:layout_height =」 370.0dip「」 - 它應該是較小的。但是當我嘗試在eclipse上將其更改爲「360」或「fill_parent」時,請簽名apk,在手機上安裝並嘗試打開該應用程序,它會崩潰。我錯過了什麼嗎?我只是試圖讓應用程序適合我的手機屏幕

遺憾的英語不好而愚蠢的問題

05-16 18:21:30.796: W/dalvikvm(11715): threadid=1: thread exiting with uncaught exception (group=0x40018560) 
05-16 18:21:31.306: E/AndroidRuntime(11715): FATAL EXCEPTION: main 
05-16 18:21:31.306: E/AndroidRuntime(11715): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.addacat.addacat/com.addacat.addacat.AddaCatActivity}: java.lang.ClassNotFoundException: com.addacat.addacat.AddaCatActivity in loader dalvik.system.PathClassLoader[/data/app/com.addacat.addacat-2.apk] 
05-16 18:21:31.306: E/AndroidRuntime(11715): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1680) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at android.app.ActivityThread.access$1500(ActivityThread.java:123) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at android.os.Handler.dispatchMessage(Handler.java:99) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at android.os.Looper.loop(Looper.java:130) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at android.app.ActivityThread.main(ActivityThread.java:3835) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at java.lang.reflect.Method.invokeNative(Native Method) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at java.lang.reflect.Method.invoke(Method.java:507) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at dalvik.system.NativeStart.main(Native Method) 
05-16 18:21:31.306: E/AndroidRuntime(11715): Caused by: java.lang.ClassNotFoundException: com.addacat.addacat.AddaCatActivity in loader dalvik.system.PathClassLoader[/data/app/com.addacat.addacat-2.apk] 
05-16 18:21:31.306: E/AndroidRuntime(11715): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at java.lang.ClassLoader.loadClass(ClassLoader.java:551) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at java.lang.ClassLoader.loadClass(ClassLoader.java:511) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at android.app.Instrumentation.newActivity(Instrumentation.java:1021) 
05-16 18:21:31.306: E/AndroidRuntime(11715): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1672) 
05-16 18:21:31.306: E/AndroidRuntime(11715): ... 11 more 

一個

package com.addacat.addacat; 

import android.app.Activity; 
import android.os.Bundle; 

public class AddaCatActivity extends Activity { 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     // TODO Auto-generated method stub 
    } 

} 

這一切都是AddaCatActivity.java

+0

您可以使用模擬器來測試您的應用程序。無需每次都簽名並安裝在手機上。 –

+0

您應該啓用從misc調試安裝。使用手機的設置來源,然後直接在手機上運行/調試應用程序。觀看logcat輸出,它肯定會詳細說明您正在處理的問題的來源。 – rekaszeru

+0

謝謝...它有很多幫助,但有一些錯誤,我不知道如何解決它們...大聲笑...我只是想改變屏幕尺寸 –

回答

0

我在一個虛擬應用程序中測試了您的佈局,使用20px x 20px圖像代替您的圖像。當我將這些高度從370dip更改爲fill_parent時,它不會崩潰。

你真的需要得到無論是仿真器或關閉您的手機,而它連接到Eclipse中運行的應用程序。您需要能夠看到LogCat。它可能會給你一個很好的想法,可能是什麼原因。


編輯:

現在你已經固定的應用程序崩潰的問題,您應該看一看this頁面。它給出了一些如何構建佈局的例子。

現在,你已經有了:

<LinearLayout> 
    <LinearLayout> // Unused 
    <RelativeLayout> 
     <ImageView /> 
     <ImageView /> 
    </RelativeLayout> 
    </LinearLayout> 

    <LinearLayout> // Unused 
    <LinearLayout> 
     <ImageButton /> 
     <ImageButton /> 
     <ImageButton /> 
     <ImageButton /> 
     <ImageButton /> 
     <ImageButton /> 
    </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 

在這一點上,至少有兩個您的LinearLayout塊看起來是未使用的。這裏有一個佈局做什麼,我想你所追求的:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <RelativeLayout 
    android:id="@+id/drag_layer" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="1" 
    android:adjustViewBounds="true" 
    android:minHeight="100.0dip" > 

    <ImageView 
     android:id="@+id/imageViewContainer" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:src="@drawable/backgsammi" 
     android:scaleType="fitCenter" 
     android:adjustViewBounds="true" /> 

    <ImageView 
     android:id="@+id/imageWatermark" 
     android:visibility="invisible" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/watermark" 
     android:layout_alignParentRight="true" /> 

    </RelativeLayout> 

    <LinearLayout 
    android:orientation="horizontal" 
    android:id="@+id/mainLLauout" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="0" > 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/open" /> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/cat" /> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/rotate" /> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/eraser" /> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/save" /> 

    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:src="@drawable/help" /> 

    </LinearLayout> 
</LinearLayout> 
+0

剛編輯主帖 –

+0

似乎有什麼東西不對應用程序名稱:com.addacat.addacat/com.addacat.addacat.AddaCatActivity –

+0

那是什麼樣子,但我不知道爲什麼會出現只有當你改變370dip到fill_parent。 – Brian

0

約像素尺寸: 1DP只在MDPI 1px的平等。在ldpi上的 ,1dp =(1 + 1/3)px。 這是因爲:mdpi是160dpi,而ldpi是120dpi。

這意味着如果您的屏幕是240x320,並且您在「layout」文件夾(如果沒有專門寫入時爲mdpi設計的)使用dp尺寸,370dp〜493像素。這比你的屏幕寬度或高度還要多。

閱讀更多信息: http://developer.android.com/guide/practices/screens_support.html

有關錯誤本身:,似乎應用程序無法找到您要啓動的活動,也許是因爲你給它改名,或者你已經把它在不同的位置。

,你需要確保你的活動是用正確的路徑清單。要確保路徑正常,請在清單上放置完整的活動路徑,而不是以「。」開頭。然後是活動的名稱。例如:

<activity android:name="com.my_awesome_app.MyAwesomeActivity" ... 
+0

以及該應用程序沒有崩潰了,並沒有在Eclipse上的錯誤,但它只是一個沒有任何關於它的黑屏 –

+0

這是一個很好的一步。現在檢查在活動的「onCreate」方法內是否有對「setContentView」的調用。如果沒有,請打電話給它,並將參數設置爲您選擇的佈局(R.layout.main)或其他您希望使用的佈局。另外,不要忘記所有的資源文件(在「res/...」中)應該是小寫的,所以你的「Main.xml」文件應該重命名爲「main.xml」 –

+0

再次檢查編輯 –