我在 TableLayout 中定义了六个按钮:-
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center" >
<Button
style="@style/CustomStyleButton2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_span="1"
android:text="Btn1" />
<Button
style="@style/CustomStyleButton2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_span="1"
android:text="Btn1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
style="@style/CustomStyleButton2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_span="1"
android:text="Btn1" />
<Button
style="@style/CustomStyleButton2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_span="1"
android:padding="5dp"
android:text="Btn1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
style="@style/CustomStyleButton2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_span="1"
android:text="Btn1" />
<Button
style="@style/CustomStyleButton2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_span="1"
android:text="Btn1" />
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
其显示是这样的:

在这里我想将所有这些按钮分开。当我应用填充或边距时,右侧的按钮不适合屏幕,并且某些部分被剪切。
这里我给第一行设置了 …
我将首先分享我的屏幕图。
每个单元格 Pij 代表为最左边的频道列中的频道 Ci 安排的节目,该频道应随网格垂直滚动。它也对应于时间线,水平滚动的时序列表(最上面的一行)。单元格宽度应与程序的持续时间成正比。
我想到的方法
我尝试了其他一些变体,但没有任何效果。stackoverflow 上也有类似的问题,但我还没有找到解决方案。这些问题的链接:
在一个 recyclerview 卷轴上滚动多个 recyclerviews
和
我对我应该为这个问题开发的方法不是很有信心。
我也考虑过使用webView 和 Html,研究它。
所以,请看一看,并给我您重要的建议和指导。
感谢您的时间。
android epg android-webview android-tablelayout android-recyclerview
首先,我进行了 Google 搜索并查看了StackOverFlow中与文本被截断相关的问题TextView。尽管它们提供了对某些事情的更好理解,但它们并没有帮助解决当前的问题。
这是我的问题。
我用来TableLayout显示带有两个文本字段的记录。每行有两个TextView单元格。对于所有单元格layout_width都设置为。wrap_content但是,即使文本以多行显示,多行文本中的每一行都会在末尾被切断。
例如
<?xml version="1.0" encoding="utf-8"?>
</TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="Notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/visitation_notes" />
<TextView
android:text="Need to visit again. Visit till the doctor understands the importance of the Test. The problem is, it is very difficult to get appointment for the visit. Still, we need to keep trying till the point reaches to him/her."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/visitation_notes_value"
android:textAlignment="viewStart"/>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
产生了视图
备注:需要再次访问。拜访直到医生 …
我正在使用TableLayout来显示数据.当活动调用onCreate()时,将设置右列TextView的文本.
现在,正如您在下图中看到的那样,我的地址文本可以很长并且应该被包装.所以我设置android:layout_width="wrap_content".但它仍然需要一个宽度的屏幕大小来包装数据.我怎样才能克服这个问题?

我的xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5px">
<TableRow>
<TextView android:text="Job#"
android:paddingRight="5px" />
<TextView android:id="@+id/DetailJobNo" />
</TableRow>
<TableRow>
<TextView android:text="Address"
android:paddingRight="5px" />
<TextView android:id="@+id/DetailAddress"
android:layout_width="wrap_content"
android:text="Address Address Address Address Address Address Address Address "/>
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud) 我有以下布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/relativeLayout1" android:layout_height="fill_parent">
<TableLayout android:id="@+id/TableLayout01" android:stretchColumns="*"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_centerInParent="true" >
<TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/syncDownload" android:layout_margin="5dp" android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:text="Download1" android:textColor="#EDFF99"
android:textStyle="bold" android:background="@drawable/custom_button" />
<Button android:id="@+id/branchesButton" android:layout_weight="1"
android:layout_margin="5dp" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Download2"
android:textColor="#EDFF99" android:textStyle="bold"
android:background="@drawable/custom_button" />
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:id="@+id/attendanceButton" android:layout_weight="1"
android:layout_margin="5dp" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Upload1"
android:textColor="#EDFF99" android:textStyle="bold"
android:background="@drawable/custom_button" />
<Button android:id="@+id/syncUpload" android:layout_margin="5dp" android:layout_weight="1"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:text="Upload2" android:textColor="#EDFF99" android:textStyle="bold"
android:background="@drawable/custom_button" />
</TableRow>
</TableLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
哪个出局

如何拉伸四个按钮以填满整个屏幕?
我学会了如何使用XML文件创建UI.但是请帮助我知道如何以编程方式执行它而不使用XML文件,尤其是除了LinearLayout之外.
我试图填充一个tablelayout与单元格和行拉伸填充整个屏幕.像这样:
http://imageshack.us/photo/my-images/69/device20120201005942.png/
在Eclipse的Graphical Layout窗口中设计的这个布局给出了我想要的东西(android:layout_weight解决了垂直拉伸):
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_weight="1">
<ImageView
android:id="@+id/imageView1"
android:layout_gravity="center"
android:src="@drawable/add" />
<ImageView
android:id="@+id/imageView2"
android:layout_gravity="center"
android:src="@drawable/bound" />
<ImageView
android:id="@+id/imageView3"
android:layout_gravity="center"
android:src="@drawable/cod" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1" >
<ImageView
android:id="@+id/imageView4"
android:layout_gravity="center"
android:src="@drawable/delete" />
<ImageView
android:id="@+id/imageView5"
android:layout_gravity="center"
android:src="@drawable/delete2" />
<ImageView
android:id="@+id/imageView6"
android:layout_gravity="center"
android:src="@drawable/floppy" />
</TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)
我试图在代码中创建相同的外观但到目前为止失败.这是我的活动的创建:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tablelo);
TableLayout tl = (TableLayout) findViewById(R.id.table);
Log.d(TAG, "Width :" + tl.getWidth());
for (int …Run Code Online (Sandbox Code Playgroud) 我里面TableLayout有多个TableRow视图.我希望以编程方式指定行的高度.例如
int rowHeight = calculateRowHeight();
TableLayout tableLayout = new TableLayout(activity);
TableRow tableRow = buildTableRow();
TableLayout.LayoutParams rowLp = new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, rowHeight);
tableLayout.addView(tableRow, rowLp);
Run Code Online (Sandbox Code Playgroud)
但这不起作用,并且默认为WRAP_CONTENT.在Android源代码中挖掘,我看到了这一点TableLayout(由onMeasure()方法触发):
private void findLargestCells(int widthMeasureSpec) {
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child instanceof TableRow) {
final TableRow row = (TableRow) child;
// forces the row's height
final ViewGroup.LayoutParams layoutParams = row.getLayoutParams();
layoutParams.height = …Run Code Online (Sandbox Code Playgroud) 我想将onClicklistener添加到生成的动态表中的项目.我的代码是
for(int k=0;k<i;k++)
{
tr[k]=new TableRow(getApplicationContext());
tr[k].layout(0, 0, 0, 0);
ids[k] = new TextView(getApplicationContext());
ids[k].setText(loc_id[k]);
ids[k].setPadding(30, 15, 30, 15);
loc[k] = new TextView(getApplicationContext());
loc[k].setText(loc_name[k]);
loc[k].setPadding(30, 15, 30 ,15);
tr[k].setPadding(0, 1, 0, 0);
tr[k].addView(ids[k]);
tr[k].addView(loc[k]);
tl.addView(tr[k], new TableLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
Run Code Online (Sandbox Code Playgroud)
请帮忙.
如何实现如下屏幕截图(1预期结果,2实际结果).正如你可以看到每个项目都有边框,它对于某些项目来说就像是左边和底部,对于某些项目来说,它是正确的和底部的.我创建了视图使用TableLayout但现在我不知道如何将边框应用于每一行和项目.我的问题是:
这是正确的方式TableLayout或应该使用GridView?
在预期的结果中,你可以看到边框是用渐变完成的,它只是淡化,所以任何人都可以为我提供可绘制的代码.
TableLayout代码:
<TableLayout
android:id="@+id/layout_pinlock_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/layout_pinlock_header"
android:layout_marginTop="@dimen/padding_15dp"
android:gravity="center_vertical"
android:padding="@dimen/padding_10dp"
android:stretchColumns="*" >
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/Tv_pinLock_01"
style="@style/TextViewMyTheme"
android:text="1" />
<TextView
android:id="@+id/Tv_pinLock_02"
style="@style/TextViewMyTheme"
android:text="2" />
<TextView
android:id="@+id/Tv_pinLock_03"
style="@style/TextViewMyTheme"
android:text="3" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/Tv_pinLock_04"
style="@style/TextViewMyTheme"
android:text="4" />
<TextView
android:id="@+id/Tv_pinLock_05"
style="@style/TextViewMyTheme"
android:text="5" />
<TextView
android:id="@+id/Tv_pinLock_06"
style="@style/TextViewMyTheme"
android:text="6" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/padding_10dp"
android:layout_marginBottom="@dimen/padding_10dp">
<TextView
android:id="@+id/Tv_pinLock_07"
style="@style/TextViewMyTheme"
android:text="7" />
<TextView
android:id="@+id/Tv_pinLock_08"
style="@style/TextViewMyTheme"
android:text="8" />
<TextView
android:id="@+id/Tv_pinLock_09"
style="@style/TextViewMyTheme"
android:text="9" />
</TableRow>
<TableRow …Run Code Online (Sandbox Code Playgroud)