我创建了一个管理我的最终用户的约会和客户的应用程序的基础。我现在正试图在设备模拟器中测试应用程序,但是当模拟器打开时,我发现除了ActionBar之外,屏幕是空白的。我没有看到我做错了什么,附上的是活动的代码:
package f454project.jack.chiropody;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
public class ApptsActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_appts);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_appts, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
和xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="f454project.jack.chiropody.ApptsActivity">
<TabHost android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabHost"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="@+id/Appointments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
<LinearLayout android:id="@+id/Patients"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
<LinearLayout android:id="@+id/Help"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
</FrameLayout>
</LinearLayout>
</TabHost>
<ListView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_gravity="center_horizontal"
android:layout_alignParentTop="true"
android:layout_marginTop="50dp"
android:layout_marginBottom="45dp"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create"
android:id="@+id/button"
android:layout_alignParentStart="false"
android:layout_alignParentTop="true"
android:layout_marginTop="450dp"
android:layout_marginLeft="140dp"
android:onClick="@string/title_activity_create_appt"/>
</RelativeLayout>
答案 0 :(得分:0)
我不确定为什么你的标签内容被添加到xml中的tabContent FrameLayout。这解决了大多数布局问题,但实际上唯一可见的是按钮,而listView的高度为0,因为它没有内容。让我知道你在这里想要达到的目标,并且我会改进我的答案。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="f454project.jack.chiropody.ApptsActivity">
<TabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_above="@+id/listView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="@+id/Appointments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/Patients"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/Help"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"/>
</FrameLayout>
</LinearLayout>
</TabHost>
<ListView
android:id="@id/listView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_above="@+id/button"/>
<Button
android:id="@id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:onClick="buttonClick"
android:text="Create"/>
</RelativeLayout>