简体   繁体   English

Tablerow内的Textview提供最高利润

[英]Textview inside tablerow is giving top margin

In my development i am placing three Textviews inside the Tablerow, those Texviews are giving some top margins due to that reason some lower case letter warping the content because Textviews are overflowing the Tablerow. 在我的开发中,我将3个Textviews放在Tablerow内,这些Texviews给出了一些高边距,原因是由于Textviews溢出了Tablerow,所以一些小写字母使内容变形。 Please suggest me the proper solution. 请建议我适当的解决方案。

Thanks in advance. 提前致谢。

<?xml version="1.0" encoding="utf-8"?>
 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:orientation="vertical" >
     <TableRow
                        android:background="#f0f"
                        android:id="@+id/tr_abspath"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Path"
                            style="@style/TextViewStyle.buddyNameTxt" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="5dp"
                            android:layout_marginRight="5dp"
                            android:text=":"
                            android:textColor="#333" />

                        <TextView
                            android:background="#ff0"
                            android:id="@+id/tv_abspath"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:includeFontPadding="false" android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.jpg"
                            android:textColor="#666" />
                    </TableRow>

                </TableLayout>

Without screenshots, it is difficult to understand exactly what issue you are experiencing. 没有屏幕截图,很难准确地了解您遇到的问题。 However, regarding the top margins, it looks like you have coded some top margins into two of your textviews: android:layout_marginTop="5dp" . 但是,关于最高边距,您似乎已经将一些最高边距编码到了两个textview中: android:layout_marginTop="5dp"

Try removing that margin to see if that fixes your issue. 尝试删除该边距,看看是否可以解决您的问题。

In your XML, you have used both margin and padding. 在XML中,您同时使用了margin和padding。 If your intention is only to set a space between the text and the table row border (Within the table row), use only padding. 如果您只是想在文本和表格行边框(表格行内)之间设置一个空格,请仅使用填充。

If your intention is to set a space between each table rows, use margin. 如果您打算在每个表行之间设置一个空格,请使用margin。

Based on the design need, please modify the code sample. 根据设计需要,请修改代码示例。 Hope this helps :) 希望这可以帮助 :)

Read this link for a clear explanation. 阅读此链接可获得清晰的说明。

Difference between a View's Padding and Margin 视图的填充和边距之间的区别

最近我也遇到了类似的问题(也尝试将边距/填充设置为0dp),并且仅当我将TextView(具有includeFontPadding = false)包装在LinearLayout(重力设置为“顶部”)中时才起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM