TableLayout 的layout_gravity问题

a156435646 2015-01-09 11:50:45

<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,1" >
<TableRow
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:background="@color/test">
<Button
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Button01"
android:text="SHORT1"
android:background="@color/test1"
/>
<Button
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Button02"
android:text="SHORT2"
android:background="@color/test2"
/>
</TableRow>
</TableLayout>



那么问题来了,为什么右边的button显示文字不全?如何才能像左边一样?
...全文
114 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
a156435646 2015-01-09
  • 打赏
  • 举报
回复
好吧,没人知道吗?我公布答案好了 android:layout_marginLeft="14dp" android:layout_marginRight="14dp" 把这两句从TableRow放到TableLayout     就OK了     <TableLayout                xmlns:android="http://schemas.android.com/apk/res/android"            xmlns:tools="http://schemas.android.com/tools"           android:layout_width="fill_parent"                 android:layout_height="fill_parent" android:layout_marginLeft="14dp" android:layout_marginRight="14dp"         android:stretchColumns="0,1" > 至于为什么,我觉得应该从源码找才能知道。。mark下吧
a156435646 2015-01-09
  • 打赏
  • 举报
回复
木有人来解决这个问题吗= =主流都不喜欢这个布局好像。。
AbsoluteLayout, RelativeLayout) res/layout/main.xml 代码 <?xml version="1.0" encoding="utf-8"?> <!-- layout_width - 宽。fill_parent: 宽度跟着父元素走;wrap_content: 宽度跟着本身的内容走;直接指定一个 px 值来设置宽 layout_height - 高。fill_parent: 高度跟着父元素走;wrap_content: 高度跟着本身的内容走;直接指定一个 px 值来设置高 --> <!-- LinearLayout - 线形布局。 orientation - 容器内元素的排列方式。vertical: 子元素们垂直排列;horizontal: 子元素们水平排列 gravity - 内容的排列形式。常用的有 top, bottom, left, right, center 等,详见文档 --> Layout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:gravity="right" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- FrameLayout - 层叠式布局。以左上角为起点,将 FrameLayout 内的元素一层覆盖一层地显示 --> <FrameLayout android:layout_height="wrap_content" android:layout_width="fill_parent"> layout_width="wrap_content" android:layout_height="wrap_content" android:text="FrameLayout"> layout_width="wrap_content" android:layout_height="wrap_content" android:text="Frame Layout"> </FrameLayout> layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello" /> <!-- TableLayout - 表格式布局。 TableRow - 表格内的行,行内每一个元素算作一列 collapseColumns - 设置 TableLayout 内的 TableRow 中需要隐藏的列的列索引,多个用“,”隔开 stretchColumns - 设置 TableLayout 内的 TableRow 中需要拉伸(该列会拉伸到所有可用空间)的列的列索引,多个用“,”隔开 shrinkColumns - 设置 TableLayout 内的 TableRow 中需要收缩(为了使其他列不会被挤到屏幕外,此列会自动收缩)的列的列索引,多个用“,”隔开 --> <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:collapseColumns="1"> layout_width="fill_parent" android:layout_height="wrap_content"> layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content" android:text="行1列1" /> layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content" android:text="行1列2" /> layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content" android:text="行1列3" /> layout_width="wrap_content" android:layout_height="wrap_content"> layout_width="wrap_content" android:layout_height="wrap_content" android:text="行2列1" /> TableLayout> <!-- AbsoluteLayout - 绝对定位布局。 layout_x - x 坐标。以左上角为顶点 layout_y - y 坐标。以左上角为顶点 --> Layout android:layout_height="wrap_content" android:layout_width="fill_parent"> layout_width="wrap_content" android:layout_height="wrap_content" android:text="AbsoluteLayout" android:layout_x="100px" android:layout_y="100px" /> Layout> <!-- RelativeLayout - 相对定位布局。 layout_centerInParent - 将当前元素放置到其容器内的水平方向和垂直方向的中央位置(类似的属性有 :layout_centerHorizontal, layout_alignParentLeft 等) layout_marginLeft - 设置当前元素相对于其容器的左侧边缘的距离 layout_below - 放置当前元素到指定的元素的下面 layout_alignRight - 当前元素与指定的元素右对齐 --> Layout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent"> layout_width="wrap_content" android:id="@+id/abc" android:layout_height="wrap_content" android:text="centerInParent=true" android:layout_centerInParent="true" /> layout_width="wrap_content" android:layout_height="wrap_content" android:text="marginLeft=20px" android:layout_marginLeft="20px" /> layout_width="wrap_content" android:layout_height="wrap_content" android:text="xxx" android:layout_below="@id/abc" android:layout_alignRight="@id/abc" /> Layout> Layout> res/values/strings.xml <?xml version="1.0" encoding="utf-8"?> Hello Layout webabcd_layout Main.java 代码 package com.webabcd.layout; import android.app.Activity; import android.os.Bundle; public class Main extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
Android 开发 (实验五) 实验题目:Android 组件布局试验 指导老师: 班 级:计算机科学与技术系班 姓 名: 一、实验目的 1、掌握 Android 组件布局的使用方法 2、学会组件布局的重要属性与应用 3、能够根据需求,通过布局构建各类实际的页面。 二、实验内容 组 件 布 局 有 : LinearLayoutTableLayout 、 FrameLayout 、 RelativeLayout 三、实验步骤 1、用表格布局完成登录界面 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFCC" android:stretchColumns="0,3" > layout_width="fill_parent" android:layout_height="5dp"/> layout_width="wrap_content" android:layout_height="100dp" android:src="@drawable/img" android:gravity="center" android:layout_span="4"/> layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="right" android:text="@string/username" android:textStyle="bold" android:textColor="#000000"/> layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="left" android:minWidth="200px" android:id="@+id/ETname"/> layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="right" android:text="@string/password" android:textStyle="bold" android:textColor="#000000"/> layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="left" android:minWidth="200px" android:inputType="textPassword" android:id="@+id/ETpwd"/>

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧