应我的Andr​​oid布局是什么样的? [英] What should my Android Layout look like?

查看:172
本文介绍了应我的Andr​​oid布局是什么样的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我问了一个有关如何添加一个视图顶部的看法,问我意识到我需要添加一个更好的布局,以我的应用程序,然后再继续之后的问题。

I recently asked a question about how to add a view on top of a view, after asking that I realized I needed to added a better layout to my app before proceeding further.

我在读 Android的布局技巧但我们注意到,它是专为文本视图和图像视图。我找了两个自定义视图来做到这一点。所以我决定掀起涂料快速图像希望更清晰地显示我想要做什么。

I was reading Android Layout Tricks but noticed it was specifically for text views and image views. I'm looking to do it with two custom views. So I decided to whip up a quick image in paint to hopefully show more clearly of what I'm wanting to do.

结果

这是我多么希望我的布局分割的意见。

This is how I want my layout to split the views. :

结果
这是它会如何看待与得出的意见。显然,紫色和蓝色的边界将是背景颜色(灰色)。以上只是数据显示具有各自的颜色绘制图表的y轴截距。 (所以将是对彼此顶部绘制多个图形视图)


This is how it would look with the views drawn. Obviously the purple and blue boundaries would be the background color (greyish). The data above simply displays the y-intercept of the graph drawn with respective color. (So there would be multiple graph views drawn on top of each other)

所以我的问题是,将我的主要内容观点是什么样子?我相信它会有一个线性布局,但我是相当新的这些布局。

So my question is, what would my main content view look like? I assume it would have a Linear layout but I'm rather new to these layouts.

修改

使用TextViews我能想出使用下面的XML类似:

Using TextViews I'm able to come up with something similar using the following XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <TextView
            android:text="Data Placeholder"
            android:background="#733674"
            android:textSize="15pt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="20"/>

        <TextView
            android:text="Graph Placeholder"
            android:background="#374F82"
            android:textSize="15pt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="80"/>

    </LinearLayout>

</LinearLayout>

所以真正剩下的就是,我应该唯一的问题用TextViews?含义我的活动我能够加入我的自定义视图而这些TextViews是谁?或者,我应该在我的自定义视图添加到XML?

So The only question that really remains is, am I supposed to use TextViews? Meaning in my Activity am I able to add my custom views where these TextViews are? Or am I supposed to add my custom view to the XML?

    <DataView
        android:text="Data Placeholder"
        android:background="#733674"
        android:textSize="15pt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="20"/>

    <GraphView
        android:text="Graph Placeholder"
        android:background="#374F82"
        android:textSize="15pt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="80"/>

我的自定义视图是用Java编写的,我不知道我怎么会让布局知道的意见所在,如果我是做这种方式。

My custom views are written in Java and I'm not sure how I would let the layout know where the views are located if I was to do it this way.

推荐答案

试试这个:的http://developer.android.com/resources/tutorials/views/hello-linearlayout.html

它有一些可能帮助你的问候layout_weight为米歇尔朴在评论中提及了非常有用的信息。

It has some very useful information which might help you out in regards to layout_weight as Michell Bak mentioned in the comment.

这是为你好浏览的页面:
http://developer.android.com/resources/tutorials/views/index.html

And here's the page for the Hello Views: http://developer.android.com/resources/tutorials/views/index.html

为了不被粗鲁,但它会更好地为您仔细阅读这些,学会对自己的XML。这样,你可以真正了解它,并能够更好地后重新创建它。

Not to be rude, but it would be much better for you to peruse these and learn the xml on your own. That way you can actually understand it and be better able to re-create it later.

我起初所有的code我不明白(包括XML文件)相当不堪重负,但稍加练习就变得非常容易 - 只需耗时

I was quite overwhelmed at first with all the code I didn't understand (including xml files), but with a little practice it becomes very easy - just time consuming.

我感到困惑最主要的是把什么样的视图中
  布局。在这些例子中,他们使用的TextView或ImageView的,但我是一个
  自定义视图

The main thing I'm confused about is what kind of View to put in the layout. In the examples they use TextView or ImageView, but mine is a custom view

那么,对于你的自定义数据视图,您将使用与 Android上的LinearLayout:layout_width =FILL_PARENT的android:layout_height = FILL_PARENT的android:layout_weight =1的android:背景=#BA4AAB(请参见 http://www.colorpicker.com/

Well, for your "Custom Data View", you would use a LinearLayout with android:layout_width="fill_parent" and android:layout_height="fill_parent" and android:layout_weight="1" and android:background="#BA4AAB" (See http://www.colorpicker.com/)

然后为您的自定义图形视图,我会用:
的android:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT机器人:layout_weight =4机器人:背景=#7D4ABA

Then for your Custom Graph View, I would use: android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="4" android:background="#7D4ABA"

注意layout_weight和背景值,我把是种猜测,你可能必须调整他们一些以适应所要的东西。

Note the layout_weight and background values I put are kind of guesses, you might have to tweak them some to match what you want.

这是我提到的是一个容量较大的LinearLayout里面有两个linearlayouts 的android:方向=垂直

The two linearlayouts that I mentioned would be inside one larger LinearLayout with android:orientation="vertical"

然后在顶部的数据,你会使用4文本视图,并在code,你会使用的setText(...)对这些文本视图把你的数据

Then for the data in the top, you would use 4 text Views, and in code, you'd use setText(...) on those text views to put your data in.

在XML进行textview1,可以添加机器人:ID =@ + ID / textview1则在code添加的TextView textview1 =(TextView中)findviewbyId(R.id.textview1); 然后 textview1.setText(myString的);

In the xml for textview1, you would add android:id="@+id/textview1" then in code add TextView textview1 = (TextView)findviewbyId(R.id.textview1); then textview1.setText(myString);

有关在底部的图表中,你可以使用2次对图形的基础上,并设置有Android版本:layout_width和android:layout_height到任何适合你使用浸,DP,或PX单元

For the graph in the bottom part, you would use 2 views for the base of the graph, and set there android:layout_width and android:layout_height to whatever suits you using dip, dp, or px units.

对于您绘制线条,相信你将不得不使用Canvas类用位图和呼叫 canvas.drawLine(...)(见<一HREF =htt​​p://developer.android.com/reference/android/graphics/Canvas.html相对=nofollow> http://developer.android.com/reference/android/graphics/Canvas.html

For the lines that you draw, I believe you would have to use the canvas class with a bitmap and call canvas.drawLine(...) (see http://developer.android.com/reference/android/graphics/Canvas.html)

这篇关于应我的Andr​​oid布局是什么样的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆