本文介绍了Android的:两个意见顶部之间通过XML的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在屏幕上显示两个视图。一个是一个随机定位点的位图。我可以得到做显示器的setContentView(...)。
我也有两个位图,并且通过XML布局语言安排一个TextView,然后使用的setContentView(R.layout.activity_title);

I want to display two views on a screen. One is a randomly positioned dot bitmaps. I can get that do display with setContentView(...).I also have two bitmaps and a textview that are arranged via xml layout language and then using setContentView(R.layout.activity_title);

DrawV.java
!!!我基本上认为我有两个setContentViews(...),我要陈列在同一时间。告诉我,如果您想了解更多信息。

DrawV.java!!!BASICALLY I THINK I HAVE TWO setContentViews(...) THAT I WANT TO DISPLAY AT THE SAME TIME. TELL ME IF YOU WANT MORE INFORMATION.

公共类DrawV扩展视图{
    变中...

public class DrawV extends View { VARIABES...

公共DrawV(上下文的背景下){
    建立社交圈(CIRCLE对象)存储视点的坐标随机选取...

public DrawV(Context context) { CREATE CIRCLES (CIRCLE OBJECTS) STORING COORDINATES RANDOMLY CHOSEN...

@覆盖
保护无效的onDraw(帆布油画){
    DRAW这些圈子位图...屏已RANDOMLY有许多点所覆盖
}

@Overrideprotected void onDraw(Canvas canvas) { DRAW THESE CIRCLES AS BITMAPS...SCREEN IS NOW RANDOMLY COVERED WITH MANY DOTS}

GameActivity.java

公共类GameActivity延伸活动{
    私人DrawV drawView;

public class GameActivity extends Activity { private 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

!!!THE WORST OFFENDER: activity_title.xml

activity_title.xml

!我不知道该怎么写。目前它没有工作。
我想在屏幕上显示两个视图。一个是一个随机定位点的位图。我可以得到做显示器的setContentView(...)。
我也有两个位图,并且通过XML布局语言安排一个TextView,然后使用的setContentView(R.layout.controls ...);

!!!I AM NOT SURE HOW TO WRITE THIS. IT DOESN'T CURRENTLY WORK.I want to display two views on a screen. One is a randomly positioned dot bitmaps. I can get that do display with setContentView(...).I also have two bitmaps and a textview that are arranged via xml layout language and then using setContentView(R.layout.controls...);

DrawV.java
!!!我基本上认为我有两个setContentViews(...),我要陈列在同一时间。告诉我,如果您想了解更多信息。

DrawV.java!!!BASICALLY I THINK I HAVE TWO setContentViews(...) THAT I WANT TO DISPLAY AT THE SAME TIME. TELL ME IF YOU WANT MORE INFORMATION.

公共类DrawV扩展视图{
    变中...

public class DrawV extends View { VARIABES...

公共DrawV(上下文的背景下){
    建立社交圈(CIRCLE对象)存储视点的坐标随机选取...

public DrawV(Context context) { CREATE CIRCLES (CIRCLE OBJECTS) STORING COORDINATES RANDOMLY CHOSEN...

@覆盖
保护无效的onDraw(帆布油画){
    DRAW这些圈子位图...屏已RANDOMLY有许多点所覆盖
}

@Overrideprotected void onDraw(Canvas canvas) { DRAW THESE CIRCLES AS BITMAPS...SCREEN IS NOW RANDOMLY COVERED WITH MANY DOTS}

GameActivity.java!STARTING .JAVA

GameActivity.java !!!STARTING .JAVA

公共类GameActivity延伸活动{
    私人DrawV drawView;

public class GameActivity extends Activity { private 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

!!!THE WORST OFFENDER: activity_title.xml

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>  

如果有人需要了解更多信息,让我知道。

If anyone needs more information, let me know.

推荐答案

XML 文件,同时声明查看的FrameLayout ,一个应该是在对方之上,应最后声明。

Inside the XML file, declare both Views inside a FrameLayout, the one that should be in top of the other, should be declared last.

要声明一个自定义创建的视图,请使用以下格式:

To declare a custom created view, use the following format:

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

这篇关于Android的:两个意见顶部之间通过XML的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 00:50