简体   繁体   English

主要活动未加载android

[英]main activity not loading android

i have designed my mainActivity, but for some reason none of my elements are showing up (i am quite new to android development) 我已经设计了mainActivity,但是由于某种原因,我的所有元素都没有显示出来(我对android开发来说还是很新的)

here is my home screen.java: 这是我的主screen.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);
    }
}

my logCat: 我的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

there is no functionality built in as of yet - i just want to ge the layout right, which is given below: 到目前为止,还没有内置任何功能-我只想让布局正确,如下所示:

    <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>

any help would be greatly appreciated. 任何帮助将不胜感激。

you must inflate your Layout!!! 您必须增加您的布局!!!

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.your_layout_name);  //i don't know the xml-filename!
}

When you create activity, it will setContentView automatically. 创建活动时,它将自动设置ContentView。 I don't know why you have no this codes. 我不知道为什么您没有此代码。

You created the activity, but did not mention which layout should be displayed or associated with the Homescreen class. 您创建了活动,但未提及应显示哪个布局或将其与Homescreen类相关联。 For that add 为此添加

setContentView(R.layout.your_homescreen_layout_name);

Brother, Put the home screen xml files name instead of your_homescreen_layout_name Happy coding.. :) 兄弟,请放置主屏幕xml文件名而不是your_homescreen_layout_name祝您编码愉快。:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM