有没有办法TableLayout完全设计风格?
我发现[这]但我想知道是否有办法将样式应用于表而不是单独的行.我有很多表,我不想单独为每一行应用样式.
我尝试将样式应用于TableLayout但是styleXML中的标记没有android:tablerow item.
如果我可以做这样的事情,那将是理想的:
<style name="Table" parent="android:Theme">
<item name="android:textSize">24sp</item>
<item name="android:padding">10dp</item>
<item name="android:tablerow">@style/TableRow</item>
</style>
Run Code Online (Sandbox Code Playgroud) 我正在用Java制作Android的gomoku游戏.
我在活动的顶部创建了一个记分牌,Button在底部创建了一个新游戏.
在中心,我创建了100 ImageView秒(10行和10列)TableLayout.它在平板电脑上工作得很好,但在手机中 - 特别是在较小的手机中 - ImageView它们太小了,你无法完美地触摸你想要的东西.
我想实现缩放功能.它可以是多点触控变焦,或者ZoomControl Button,我唯一需要的就是工作.所以我想放大并缩小TableLayout,但记分牌和新游戏Button都没有做任何事情.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical" >
<TableRow
android:id="@+id/tableRowE"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:paddingTop="5dip"
android:paddingBottom="10dip"
android:gravity="center" >
<TextView
android:id="@+id/twScoreboard"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/result"
android:textSize="20sp"
android:layout_span="10"
android:gravity="center"
/>
</TableRow>
<TableRow
android:id="@+id/tableRow0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dip"
android:paddingLeft="5dip"
android:gravity="center" >
<ImageView
android:id="@+id/ImageView1"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/empty"
android:textSize="20sp" />
<ImageView
android:id="@+id/ImageView2"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/empty" …Run Code Online (Sandbox Code Playgroud) http://img683.imageshack.us/img683/645/weatherscreenmockupoutl.png
我问自己什么是编码这种布局的最佳方法.基本上我只需要知道如何获得具有相等宽度的七列.
提前致谢!

我设法使用设计布局TableLayout.android:layout_span帮助我.
问题是我需要Column1和Column2之间的一些差距.无论哪种方式Padding / Margin
我不喜欢这个任务的程序.必须有一个简单的方法来做到这一点.
可以使用xml设置吗?
更新:我试图设置列子的填充它没有均匀地对齐列.
我有一个 TableLayout,我以编程方式添加行,我试图以编程方式设置行中包含的元素的“权重”。
我试图通过weightSum在 TableRow 上设置并使用“LayoutParams”的最后一个参数设置列的“权重”来做到这一点,但什么也没出现;相反,如果我给元素一个固定的宽度,代码运行良好。
这是我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/sample"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center" >
</TableLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是代码:
public class HomeFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.home, null);
}
@Override
public void onStart() {
super.onStart();
TableLayout tl = (TableLayout)getActivity().findViewById(R.id.sample);
TableRow tr = new TableRow(getActivity());
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
tr.setGravity(Gravity.CENTER);
tr.setWeightSum(1f);
TableRow.LayoutParams lp;
TextView tv1 = new TextView(getActivity());
lp = new TableRow.LayoutParams(0, TableRow.LayoutParams.WRAP_CONTENT, 0.6f);
tv1.setText("AAA");
tv1.setLayoutParams(lp); …Run Code Online (Sandbox Code Playgroud) 我有如下布局:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SettingsActivity" >
<TableRow
...
</TableRow>
<TableRow
...
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Temperature:" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
Run Code Online (Sandbox Code Playgroud)
在第三个中TableRow,TextView和SeekBar平分空间。我希望 theTextView仅与其中的文本一样宽,并且SeekBar应该填充其余空间。我试过摆弄重力、宽度和重量。获得这种行为的最佳方法是什么?
我在 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。但是当我尝试在 Lollipop 上运行相同的活动时,它崩溃了。
它适用于棉花糖和牛轧糖。
当我在删除 TableLayout(ONLY) 后尝试运行它时,它在 Lollipop 中也运行良好。
我尝试删除活动中的所有 java 代码,它有同样的问题。
我的崩溃报告
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.sovereignconsult.region.viand, PID: 19434 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getVisibility()' on a null object reference at android.widget.LinearLayout.forceUniformHeight(LinearLayout.java:1380) at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1368) at android.widget.TableRow.onMeasure(TableRow.java:114) at android.view.View .measure(View.java:17826) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) at android。widget.TableLayout.measureChildBeforeLayout(TableLayout.java:464) at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) at android.widget.TableLayout.measureVertical(TableLayout.java:476) at android.widget.TableLayout.onMeasure (TableLayout.java:439) at android.view.View.measure(View.java:17826) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java: 464) 在 android.view.View.measure(View.java:17826) 在 android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1269) 在 android.widget.FrameLayout.onMeasure(FrameLayout.java:430) 在 android.widget.ScrollView.onMeasure(ScrollView.java:338) 在 android.view.View.measure(View.java:17826) 在 android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728) 在 android。 widget.RelativeLayout.onMeasure(RelativeLayout.java:464) at …