-2

I am a beginner and I am working on a simple app. I have 2 pictures on the top of the screen, and one LinearLayout in the bottom all of them are assigned by "android:layout_marginTop...". The problem is, I have tried that on my sony xperia x8(320 x 480 pixels, 3.0 inches ) and the mainmenu which has 3 images(buttons) are being pushed off the screen, please help. And it does not work on the android emulator I can't open it in the emulator but I can on my phone. it says: "This.....app has stopped unexpectedly"

This is how I want it to look like:

https://docs.google.com/a/seoulforeign.com/file/d/0Byv_19fXkk1MaGtZR3Y3Z1lsNk0/edit

This is how it looks on my sony x8 screen

https://docs.google.com/a/seoulforeign.com/file/d/0Byv_19fXkk1MaE5RazNGdVF2eHM/edit

MinSDK :2.1 Target : 4.2

Here is my main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mainbg"
android:orientation="vertical"
tools:context=".MainActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="220dp"
    android:layout_height="50dp"
    android:layout_gravity="left"
    android:layout_marginLeft="-5dp"
    android:layout_marginTop="10dp"
    android:scaleType="centerCrop"
    android:src="@drawable/headingmain" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="300dp"
    android:layout_height="20dp"
    android:layout_gravity="right"
    android:layout_marginRight="-83dp"
    android:layout_marginTop="-12dp"
    android:scaleType="centerCrop"
    android:src="@drawable/headingby" />

<LinearLayout
  android:layout_weight="-30"
  android:id="@+id/MainMenu"
  android:layout_width="200dp"
  android:layout_height="200dp"
  android:layout_gravity="center"
  android:layout_marginTop="275dp"
  android:gravity="center"
  android:orientation="vertical" >

 <ImageButton
      android:id="@+id/imageButton1"
      android:layout_width="180dp"
      android:layout_height="55dp"
      android:background="@drawable/playbutton"
      android:padding="0dp"
      android:scaleType="centerCrop"
      android:src="@drawable/playbutton" />

 <ImageButton
      android:id="@+id/imageButton2"
      android:layout_width="180dp"
      android:layout_height="55dp"
      android:background="@drawable/helpbutton"
      android:padding="0dp"
      android:scaleType="centerCrop"
      android:src="@drawable/helpbutton" />

  <ImageButton
      android:id="@+id/imageButton3"
      android:layout_width="180dp"
      android:layout_height="55dp"
      android:background="@drawable/aboutbutton"
      android:padding="0dp"
      android:scaleType="centerCrop"
      android:src="@drawable/aboutbutton" />

    <!--  end of main menu! -->
    </LinearLayout>  


    </LinearLayout>
4

2 回答 2

0

在这种情况下,菜单 LinearLayout 上的边距顶部将是从第二张图像底部的偏移量 - 您不能假设知道第二张图像底部和屏幕底部之间的距离,所以不要尝试放置事情是这样的。负权重将被忽略。

此外,听起来您的菜单栏正在复制 iOS 功能,请使用 Android 等效项 - http://developer.android.com/design/patterns/actionbar.html ActionBar 在旧 Android 版本的支持库中可用

于 2013-09-16T07:38:07.180 回答
0

看看这是我为你尝试过的

我的清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.testandroid"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.testandroid.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

    </application>

</manifest>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/mainbg"
android:orientation="vertical"
tools:context=".MainActivity" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="220dp"
    android:layout_height="50dp"
    android:layout_gravity="left"
    android:layout_marginLeft="-5dp"
    android:layout_marginTop="10dp"
    android:scaleType="centerCrop"
    android:src="@drawable/headingmain" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="300dp"
    android:layout_height="20dp"
    android:layout_gravity="right"
    android:layout_marginLeft="304dp"
    android:scaleType="centerCrop"
    android:src="@drawable/headingby" />

<LinearLayout
    android:id="@+id/MainMenu"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_marginTop="120dp"
    android:gravity="center"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:layout_marginTop="12dp"
        android:src="@drawable/playbutton" />

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="22dp"
        android:src="@drawable/playbutton" />

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:src="@drawable/playbutton" />

    <!-- end of main menu! -->
</LinearLayout>

于 2013-09-16T08:08:30.670 回答