0

我正在升级我的应用程序以包含操作栏,我对格式有点困惑。

所以第一个活动看起来不错,这里是代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" 
android:layout_height="match_parent">

<TextView  
    android:id="@+id/main_title"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/main_title"
    android:textSize="24sp" 
    android:textColor="@color/orange"
    android:textStyle="bold"
    android:gravity="center_vertical|center_horizontal" 
    android:padding="20dp"/>
    <Button 
    android:id="@+id/new_inspection" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/main_title"
    android:text="@string/create_new_inspection"/>
    <TextView  
    android:id="@+id/saved_inspections"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/new_inspection"
    android:text="@string/saved_inspections" 
    android:padding="5dp"/>
    <ListView 
    android:id="@id/android:list" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/saved_inspections"/>
    <TextView  
    android:id="@id/android:empty"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/no_saved_inspections"
    android:gravity="center" 
    android:padding="20dp"
    android:layout_below="@id/saved_inspections"/>
</RelativeLayout>

OnCreate 方法:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_inspection);
    setUpViews();
    setLongClick();
    rmDbHelper = new RMDbAdapter(this);
    rmDbHelper.open();
    Cursor listCursor = rmDbHelper.fetchAllInspections();
    startManagingCursor(listCursor);           
    setListAdapter(new MyListAdapter(this, listCursor));  
}

看起来像这样:

正确的布局

但是其他一些活动看起来不像这样,我不知道为什么 - 例如,这是下一个活动的代码:

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

<RelativeLayout
android:id="@+id/heading_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
    <TextView  
    android:id="@+id/main_title"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/main_title" 
    android:textSize="18sp"
    android:textStyle="bold" 
    android:textColor="@color/orange"
    android:gravity="center_vertical|center_horizontal" 
    android:padding="5dp"/>
    <TextView  
    android:id="@+id/secondary_title"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/main_title"
    android:text="@string/secondary_title"
    android:textStyle="bold" 
    android:gravity="center_vertical|center_horizontal" 
    android:padding="5dp"/>
    <Button 
    android:id="@+id/new_run" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/secondary_title"
    android:text="@string/create_new_run"/>
    <TextView  
    android:id="@+id/saved_runs"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/new_run"
    android:text="@string/saved_runs" 
    android:padding="5dp"/>
</RelativeLayout>

<LinearLayout
android:id="@+id/complete_button_layout" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
    <Button
    android:id="@+id/complete_button"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/run_area_complete"
    android:padding="5dp"/>
</LinearLayout>

<ListView 
android:id="@id/android:list" 
android:layout_width="fill_parent" 
android:layout_height="0dp"
android:layout_below="@id/heading_layout"
android:layout_above="@id/complete_button_layout"/>
<TextView  
android:id="@id/android:empty"
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="@string/no_saved_runs"
android:layout_centerHorizontal="true"
android:padding="20dp"
android:layout_below="@id/heading_layout"
android:layout_above="@id/complete_button_layout"/> 

</RelativeLayout>

OnCreate 为此:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_run);
    rmDbHelper = new RMDbAdapter(this);
    rmDbHelper.open();
    Intent i = getIntent();
    inspectionId = i.getLongExtra("Intent_InspectionID", -1);
    areaId = i.getLongExtra("Intent_AreaID", -1);
    setUpViews();
    setLongClick();
    Cursor listCursor = rmDbHelper.fetchAllRunsForArea(areaId);
    startManagingCursor(listCursor);           
    setListAdapter(new MyListAdapter(this, listCursor));
}

看起来像这样:

布局不正确

商店里到处都是颜色,我看不出 xml 文件有什么不同。

这是信息清单:

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

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

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

<application
    android:icon="@drawable/logo"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Holo" >
    <activity
        android:name=".InspectionActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        android:label="@string/title_activity_inspection" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".InspectionEdit"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"/>
    <activity android:name=".AreaActivity"
        android:screenOrientation="portrait"/>
    <activity android:name=".AreaEdit"
        android:screenOrientation="portrait"/>
    <activity android:name=".RunActivity"
        android:screenOrientation="portrait"/>
    <activity android:name=".RunEdit"
        android:screenOrientation="portrait"/>
    <activity android:name=".LocationActivity"
        android:screenOrientation="portrait"/>
    <activity android:name=".ComponentEdit"
        android:screenOrientation="portrait"/>
    <activity android:name=".IssueActivity"
        android:screenOrientation="portrait"/>
    <activity android:name=".IssueEdit"
        android:screenOrientation="portrait"/>
    <activity android:name=".SpecificationEdit"
        android:screenOrientation="portrait"/>
    <activity android:name=".ExportActivity"
        android:screenOrientation="portrait"/>

</application>

</manifest>
4

1 回答 1

-2

只需将父布局的背景颜色设置为黑色:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@android:color/black">

或将您的应用主题设置为:

Theme.Black.NoTitleBar

比希望它看起来不错。

于 2013-02-11T12:49:26.517 回答