我正在尝试获取视图左上角的绝对屏幕像素坐标.但是,我可以找到的所有方法,例如getLeft()
并且getRight()
不起作用,因为它们似乎都相对于视图的父级,因此给了我0
.这样做的正确方法是什么?
如果它有帮助,这是为了"让图片重新整理"游戏.我希望用户能够绘制一个框来选择多个部分.我的假设是,做到这一点的最简单方法是getRawX()
,并getRawY()
从MotionEvent
再兑布局保持件的左上角比较这些值.知道了件的大小,我就可以确定已经选择了多少件.我知道我可以使用getX()
和getY()
上MotionEvent
,而是作为一个返回相对位置,使得确定哪个被选择件更困难.(我知道,这并非不可能,但似乎不必要地复杂化).
编辑:这是我用来尝试获取保持容器大小的代码,根据其中一个问题.TableLayout
是包含所有拼图的表.
TableLayout tableLayout = (TableLayout) findViewById(R.id.tableLayout);
Log.d(LOG_TAG, "Values " + tableLayout.getTop() + tableLayout.getLeft());
Run Code Online (Sandbox Code Playgroud)
编辑2:这是我尝试过的代码,遵循更多建议的答案.
public int[] tableLayoutCorners = new int[2];
(...)
TableLayout tableLayout = (TableLayout) findViewById(R.id.tableLayout);
tableLayout.requestLayout();
Rect corners = new Rect();
tableLayout.getLocalVisibleRect(corners);
Log.d(LOG_TAG, "Top left " + corners.top + ", " + corners.left + ", " + corners.right
+ ", " + corners.bottom);
cells[4].getLocationOnScreen(tableLayoutCorners);
Log.d(LOG_TAG, "Values " …
Run Code Online (Sandbox Code Playgroud) 我想custom adapter
为我的列表视图创建一个.是否有任何文章可以指导我如何创建一个并解释它是如何工作的?
我在Android中使用TableLayout.现在我有一个TableRow,里面有两个项目,在它下面是一个TableRow,它有一个项目.它呈现如下:
-----------------------------
| Cell 1 | Cell 2 |
-----------------------------
| Cell 3 |
---------------
Run Code Online (Sandbox Code Playgroud)
我想要做的是让Cell 3延伸到两个上部单元格,所以它看起来像这样:
-----------------------------
| Cell 1 | Cell 2 |
-----------------------------
| Cell 3 |
-----------------------------
Run Code Online (Sandbox Code Playgroud)
在HTML中我会使用COLSPAN ....如何在Android中使用它?
我android.support.design.widget.TabLayout
在我的应用程序中使用了Min SDK 15.
默认情况下,它采用大写字母标题,但我希望它在"textCapsWord"中生成.我尝试在这里和这里建议添加Style .但不幸的是两者都行不通.
tabs android gwt-tablayoutpanel android-tablelayout android-design-library
请看这里的XML代码:
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Some stuff goes here -->
/>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Some stuff goes here -->
/>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Some stuff goes here -->
/>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
我的代码比这长得多,但我只是删除了不必要的部分.问题是我想让它成为TableLayout
一个可滚动的,这样我的所有东西都可以显示出来.
我试图将此行放入其中TableLayout
以使其可滚动:
android:isScrollContainer="true"
Run Code Online (Sandbox Code Playgroud)
但它没有做到这一点.有办法吗?
它在TableLayout的文档中说"单元格可以跨越列,就像它们可以在HTML中一样".但是,我找不到任何办法.
具体来说,我有一行有两列,另一行有一列.我希望一列行跨越整个表.看起来很简单,但我没有看到它.
这是我的XML for LAND格式的一部分:
<TableLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:stretchColumns="*">
<TableRow>
<Button
android:id="@+id/countbutton"
android:text="@string/plus1"/>
<Button
android:id="@+id/resetbutton"
android:text="@string/reset"
/>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
现在我得到的东西 - 一行的宽度和按钮的宽度取决于按钮内的TEXT.如果这两个文本都是等长的,那就说:TEXT它没关系 - 表格的一半位于屏幕中间.但如果它们有不同的尺寸 - 让我们说"A"和"这就是长按钮",桌子的中心不再在屏幕中间,所以按钮宽度不一样......
我现在真的很困惑要学习哪一个.我是一名iPhone应用程序开发人员,现在正在学习Android开发.
我已经学会了如何使用ListView
带有静态字符串的字符串Adapter
.我习惯在iPhone中使用自定义单元格,主要用于显示TableView
s中的图像和文本等动态内容.
那么在Android中这样做的方法是什么?TableLayout
还是ListView
?
android custom-cell android-listview android-adapter android-tablelayout
我正在学习机器人并且正在努力探索这个特定的布局属性,阅读谷歌开发文档它说:
android:layout_column
Run Code Online (Sandbox Code Playgroud)
该子项应该在的列的索引.必须是整数值,例如"100".这也可以是对资源的引用(其形式为"@〔包:]类型:名称为")("?[包:] [类型:]名称"的形式)或主题属性包含该类型的值.这对应于全局属性资源符号layout_column.
任何人都可以解释这是如何映射到一个html等价物(因为表格行似乎从他们那里大量借用)?
这是它所采用的柱数 - 例如colspan?
我想绘制一个表,其中最后一列应位于表的最右侧.
这是表行的样子:
Admin (2)New
Network (2)New
Run Code Online (Sandbox Code Playgroud)
这应该是这样的:
Admin (2) New
Network (2) New
Run Code Online (Sandbox Code Playgroud)
XML:
<?xml version="1.0" encoding="utf-8"?>
<!-- row.xml -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="45dp"
android:gravity="center" android:background="@color/list_bg">
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<ImageView android:id="@+id/t1" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="@+id/t2" android:typeface="normal"
android:singleLine="true" android:textSize="14sp" android:textStyle="normal"
android:layout_width="wrap_content" android:textColor="#000000"
android:layout_height="wrap_content" />
<TextView android:id="@+id/t10" android:typeface="normal"
android:singleLine="true" android:text=" " android:textSize="14sp"
android:textStyle="normal" android:layout_width="wrap_content"
android:textColor="#000000" android:layout_height="wrap_content" />
<TextView android:id="@+id/t4" android:typeface="normal"
android:visibility="gone" android:singleLine="true" android:text="("
android:textSize="14sp" android:textStyle="normal"
android:layout_width="wrap_content" android:textColor="#000000"
android:layout_height="wrap_content" />
<TextView android:id="@+id/t5" android:typeface="normal"
android:visibility="gone" android:singleLine="true"
android:textSize="14sp" android:textStyle="normal"
android:layout_width="wrap_content" android:textColor="#000000"
android:layout_height="wrap_content" /> …
Run Code Online (Sandbox Code Playgroud)