相同的xml代码,不同的图形布局

时间:2014-12-18 14:42:52

标签: android xml

我是Android开发的新手,我尝试从另一个项目复制xml布局,但该xml的图形布局似乎与我得到的不同。我不知道我的项目中缺少什么,我没有得到相同的布局。请帮忙。

这就是它的样子

1

这是我在复制确切代码后得到的结果。

2

我的xml文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.aditya.contentsharer"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="21" />

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

    <uses-feature android:name="android.hardware.camera" />

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

    <application
        android:name=".InteriorSpottingApplication"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".InteriorListActivity"
            android:label="@string/title_activity_interior_list" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="android.app.Activity" />
        </activity>
        <activity
            android:name=".NewInteriorActivity"
            android:label="@string/title_activity_new_interior" >
        </activity>
    </application>

</manifest>

xml代码

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragmentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

java代码

package com.aditya.contentsharer;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.ParseQueryAdapter;

public class InteriorListActivity extends ListActivity{

    private ParseQueryAdapter<Interior> mainAdapter;
    private FavoriteInteriorAdapter favoritesAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getListView().setClickable(false);

        mainAdapter = new ParseQueryAdapter<Interior>(this, Interior.class);
        mainAdapter.setTextKey("title");
        mainAdapter.setImageKey("photo");

        // Subclass of ParseQueryAdapter
        favoritesAdapter = new FavoriteInteriorAdapter(this);

        // Default view is all interiors
        setListAdapter(mainAdapter);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_interior_list, menu);
        return true;
    }

    /*
     * Posting interiors and refreshing the list will be controlled from the Action
     * Bar.
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

        case R.id.action_refresh: {
            updateinteriorList();
            break;
        }

        case R.id.action_favorites: {
            showFavorites();
            break;
        }

        case R.id.action_new: {
            newinterior();
            break;
        }
        }
        return super.onOptionsItemSelected(item);
    }

    private void updateinteriorList() {
        mainAdapter.loadObjects();
        setListAdapter(mainAdapter);
    }

    private void showFavorites() {
        favoritesAdapter.loadObjects();
        setListAdapter(favoritesAdapter);
    }

    private void newinterior() {
        Intent i = new Intent(this, NewInteriorActivity.class);
        startActivityForResult(i, 0);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            // If a new post has been added, update
            // the list of posts
            updateinteriorList();
        }
    }

}

2 个答案:

答案 0 :(得分:0)

我得到了解决方案。我从清单文件中删除了android:theme =“@ style / AppTheme”。这对我来说很好。

答案 1 :(得分:0)

我不习惯处理ListActivities,因为我通常在正常活动中使用ListView,但我的第一个猜测是你仍需要在onCreate()方法中使用这样的一行来实际获得任何布局。 ..

setContentView(R.layout.fragmentContainer);

(假设您的xml文件名称与其ID相同?

尝试将其放在

之后
super.onCreate(savedInstanceState);

我不确定它是否会起作用但是试试吧! :)