2014-06-10 62 views
-2

我想在屏幕上顯示兩個視圖。一個是隨機定位的點位圖。我可以用setContentView(...)來顯示。 我也有兩個位圖和一個textview,它們是通過xml佈局語言進行排列,然後使用setContentView(R.layout.activity_title);Android:使用XML的彼此之間的兩個視圖


DrawV.java !!!我基本上認爲我有兩個setContentViews(...),我要陳列在同一時間。告訴我,如果你想知道更多的信息。


公共類DrawV擴展視圖{ 變中......

公共DrawV(上下文的背景下){ 建立社交圈(CIRCLE對象)存儲視點的座標隨機選擇...

@覆蓋 保護無效onDraw(畫布畫布){ 將這些圈子畫成BITMAPS ...畫面現在隨機覆蓋很多個點 }


GameActivity.java


公共類GameActivity延伸活動{ 私人DrawV drawView函數;

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    drawView = new DrawV(this); 
    setContentView(R.layout.activity_title); !!!SHOWS LAYOUT (HOPEFULLY TEXTVIEW, TWO BUTTONS, AND RANDOMLY POSITIONED DOTS (DOTS NEVER WORKS) WHICH IS OVERDONE BY DRAWVIEW... 
    setContentView(drawView); !!!IF THIS STATEMENT IS SECOND IT RENDERS INTEAD OF THE PREVIOUS STATEMENT. OTHERWISE activity_title shows. 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    DEFAULT CODE... 
} 

}

!!!罪魁禍首:activity_title.xml


activity_title.xml


!!!我是不知道如何寫這個。它目前不工作。 我想在屏幕上顯示兩個視圖。一個是隨機定位的點位圖。我可以用setContentView(...)來顯示。 我也有兩個位圖和一個textview,通過XML佈局語言,然後使用setContentView(R.layout.controls ...);


DrawV.java !!!我基本上認爲我有兩個setContentViews(...),我要陳列在同一時間。告訴我,如果你想知道更多的信息。


公共類DrawV擴展視圖{ 變中......

公共DrawV(上下文的背景下){ 建立社交圈(CIRCLE對象)存儲視點的座標隨機選擇...

@覆蓋 保護無效onDraw(畫布畫布){ 繪製這些圓形作爲位圖...屏已RANDOMLY有許多點 }


GameActivity.java涵蓋的!STARTING .JAVA


公共類GameActivity延伸活動{ 私人DrawV drawView函數;

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    drawView = new DrawV(this); 
    setContentView(R.layout.activity_title); !!!SHOWS LAYOUT (HOPEFULLY TEXTVIEW, TWO BUTTONS, AND RANDOMLY POSITIONED DOTS (DOTS NEVER WORKS) WHICH IS OVERDONE BY DRAWVIEW... 
    setContentView(drawView); !!!IF THIS STATEMENT IS SECOND IT RENDERS INTEAD OF THE PREVIOUS STATEMENT. OTHERWISE activity_title shows. 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    DEFAULT CODE... 
} 

}

!!!罪魁禍首:activity_title.xml


activity_title.xml


!!!I AM NOT SURE HOW TO WRITE THIS. IT DOESN'T CURRENTLY WORK. 
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:gravity="center" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="20dp" > 
       <TextView 
       android:textColor="#ff0000" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:textSize="40sp" 
       android:text="@string/timer" 
       android:id="@+id/timer"> 
       </TextView> 
       <LinearLayout 
       android:orientation="horizontal" 
       android:layout_gravity="center_horizontal" 
       android:gravity="center" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content"> 
<Button 
        android:layout_marginLeft="20dp" 
        android:background="@drawable/stopbutton" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_weight="1" 
        android:text="@string/stopText" 
        android:id="@+id/stopButton" 
        android:visibility="gone"> 
        </Button> 
        <Button 
        android:layout_marginLeft="20dp" 
        android:background="@drawable/startbutton" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_weight="1" 
        android:text="@string/startText" 
        android:id="@+id/startButton"> 
        </Button> 
        <Button 
        android:layout_marginRight="20dp" 
        android:background="@drawable/resetbutton" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_weight="1"     
        android:text="@string/resetText" 
        android:id="@+id/resetButton"> 
        </Button> 
       </LinearLayout> 
      </LinearLayout> 

      <LinearLayout !!!MESSED UP CODE. DON'T KNOW HOW TO SHOW DOTS USING XML 
      android:orientation="horizontal" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal"> 
       <View class="com.category.tap.DrawV" 
       android:id="@+id/dotpic" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" /> 
      </LinearLayout> 


</RelativeLayout> 

如果有人需要更多的信息,讓我知道。

+0

嘗試使用'CTRL + k'突出的代碼,因爲它是很難讀 –

+0

如何使東西查看?我是否需要更改View或RelativeLayout或FrameLayout或以上所有內容? – user963070

+0

使用RelativeLayout! –

回答

0

如果您想堆疊兩種佈局,請先將它們添加到FrameLayout

+0

你究竟使用什麼?你在每個佈局外只放置嗎?你使用它兩次還是一次? – user963070

+0

你使用它一次,並把你的其他兩個佈局 – MrEngineer13

0

可以使用堆疊視圖relaivelayout或framelayout。這些佈局支持z-index佈局,因此視圖可以相互重疊。在同一活動中不能有兩個setcontentview。要在屏幕上顯示一個點,你也可以這樣做:

<View android:layout_height="1dp" 
     android:layout_width="1dp" 
     android:background="@android:color/black"/> 
+0

真的嗎?我只能爲一切使用一種佈局?知道肯定會給我帶來很多麻煩。 – user963070

+0

如果我在其他地方發佈一個小清潔工,我會陷入困境嗎? – user963070

+0

@ user963070我們鼓勵你發佈它,你不會遇到任何麻煩,但是這是一個很好的做法(不要求)提及原始來源。 –

3

裏面的XML文件,同時聲明Views一個FrameLayout裏面,一個應該是在另一個的上面,應該聲明最後。

要聲明一個自定義創建視圖,請使用以下格式:

<com.mypackage.MyCustomView 
    android:layout_width=...... 
+0

給我一個錯誤:「應用程序TAP(proess com.category.tap)已經意外停止,請重試。 – user963070

+0

發佈您的logcat –

+0

這是我使用com的錯誤...否則錯誤是:[2014-06-11 16:40:31 - TAP] ActivityManager:啓動:Intent {act = android.intent.action。MAIN cat = [android.intent.category.LAUNCHER] cmp = com.category.tap/.GameActivity} [2014-06-11 16:40:31 - TAP] ActivityManager:警告:活動未啓動,其當前任務有被帶到前面 – user963070