我设计了我的mainActivity,但由于某些原因,我的元素都没有显示出来(我对android开发很新)
这是我的主屏幕.java:
public class HomeScreen extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home_screen, 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我的logCat:
09-11 13:45:42.359 1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour E/dalvikvm﹕ could not disable core file generation for pid 1935: Operation not permitted
09-11 13:45:43.460 1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed 114K, 47% free 2782K/5191K, external 2441K/2773K, paused 119ms
09-11 13:45:43.585 1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed 4K, 47% free 2783K/5191K, external 3178K/3481K, paused 93ms
09-11 13:45:43.742 1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed <1K, 47% free 2785K/5191K, external 3618K/4030K, paused 118ms
09-11 13:45:44.031 1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour D/dalvikvm﹕ GC_EXTERNAL_ALLOC freed <1K, 47% free 2789K/5191K, external 4497K/4579K, paused 129ms
09-11 15:18:36.725 1935-1935/au.gov.nsw.shellharbour.saferroadsshellharbour D/dalvikvm﹕ GC_EXPLICIT freed 421K, 50% free 2869K/5639K, external 4545K/5676K, paused 99ms
目前还没有内置的功能 - 我只是想正确布局,如下所示:
<LinearLayout 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:orientation="vertical"
tools:context=".HomeScreen">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:orientation="horizontal">
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:text="Latitude: "
android:textSize="20dip"/>
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unknown"
android:textSize="20dip"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginRight="5dip"
android:text="Longitude"
android:textSize="20dip"/>
<TextView
android:id="@+id/TextView04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="unkown"
android:textSize="20dip"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="259dp"
android:id="@+id/scrollView"
android:layout_gravity="center_vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<ImageButton
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/btn_dob_in_a_hoon"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:src="@drawable/dobinahoonmenu"/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/btn_report_a_hazard"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:src="@drawable/reportahazardmenu"/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/btn_Old_logo"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:src="@drawable/oldlogomenu"/>
<ImageButton
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/btn_Council_Website"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:src="@drawable/councilwebsitemenu"/>
</LinearLayout>
</ScrollView>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/horizontalScrollView2" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="51dp"
android:layout_gravity="center_horizontal|bottom">
<ImageButton
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="@+id/facebook"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:src="@drawable/facebookbutton"
android:scaleType="fitCenter"/>
<ImageButton
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="@+id/twitter"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:src="@drawable/scclogoold"
android:scaleType="fitCenter"/>
<ImageButton
android:layout_width="60dp"
android:layout_height="match_parent"
android:id="@+id/contact"
android:layout_gravity="center_horizontal"
android:clickable="true"
android:src="@drawable/contactbutton"
android:scaleType="fitCenter"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
任何帮助将不胜感激。
答案 0 :(得分:0)
你必须给你的布局充气!!!
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout_name); //i don't know the xml-filename!
}
答案 1 :(得分:0)
创建活动时,它会自动设置内容。我不知道为什么你没有这个代码。
答案 2 :(得分:0)
您创建了活动,但未提及应显示哪个布局或与Homescreen
类关联。为此添加
setContentView(R.layout.your_homescreen_layout_name);
兄弟,将主屏幕xml文件名称替换为your_homescreen_layout_name 快乐的编码.. :)