当我不知道两个视图的文本量时如何对齐?

如何解决当我不知道两个视图的文本量时如何对齐?

| 我有两个要对齐其高度的EditText视图。问题是我无法预测哪个视图将包含更多文本,因此使用
android:layout_alignTop
android:layout_alignBottom
将不起作用。我正在尝试的布局如下。我已经尝试过
android:layout_alignTop
android:layoutAlignBottom
,但结果却不令人满意。 版式1
<?xml version=\"1.0\" encoding=\"utf-8\"?>

<RelativeLayout 
xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\" 
android:layout_height=\"fill_parent\">

<EditText
        android:id=\"@+id/text1\" 
        android:layout_width=\"200dip\"
        android:layout_height=\"wrap_content\"
        android:layout_alignParentLeft=\"true\"           
        android:padding=\"5dip\"

        android:text=\"Text 1 bvhg hbjbj kjkbkj kjnjkn hlihj lklkkl\"
        />

<EditText
        android:id=\"@+id/text2\" 
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\"
        android:layout_toRightOf=\"@+id/text1\"           
        android:padding=\"5dip\"

        android:text=\"Text 2 lasndklsa lkmsclslk klmsldmlk lksdl\"
        />


</RelativeLayout>
布局1的图:http://imgur.com/P6KV7.png 具有
android:layout_alignTop
android:layout_alignBottom
的布局2
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<RelativeLayout 
xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\" 
android:layout_height=\"fill_parent\">

<EditText
        android:id=\"@+id/text1\" 
        android:layout_width=\"200dip\"
        android:layout_height=\"wrap_content\"
        android:layout_alignParentLeft=\"true\"   
        android:layout_alignTop=\"@+id/text2\"
        android:layout_alignBottom=\"@+id/text2\"

        android:padding=\"5dip\"

        android:text=\"Text 1 bvhg hbjbj kjkbkj kjnjkn hlihj lklkkl\"
        />

<EditText
        android:id=\"@+id/text2\" 
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\"
        android:layout_toRightOf=\"@+id/text1\"           
        android:padding=\"5dip\"

        android:text=\"Text 2 lasndklsa lkmsclslk klmsldmlk lksdl\"
        />


</RelativeLayout>
布局2的图:http://imgur.com/x6fyI.png 但是,如果我要更改第一个EditText上的文本,则该框中的某些文本会被截断。请参见下面的布局3和图3: 版式3
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<RelativeLayout 
xmlns:android=\"http://schemas.android.com/apk/res/android\"
android:layout_width=\"fill_parent\" 
android:layout_height=\"fill_parent\">

<EditText
        android:id=\"@+id/text1\" 
        android:layout_width=\"200dip\"
        android:layout_height=\"wrap_content\"
        android:layout_alignParentLeft=\"true\"   
        android:layout_alignTop=\"@+id/text2\"
        android:layout_alignBottom=\"@+id/text2\"

        android:padding=\"5dip\"

        android:text=\"Text 1 bvhg hbjbj kjkbkj kjnjkn hlihj lklkkl
                    1 bvhg hbjbj kjkbkj kjnjkn hlihj lklkkl    ncksjcksn
                    lkslksldcsdc
                    the end\"
        />

<EditText
        android:id=\"@+id/text2\" 
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\"
        android:layout_toRightOf=\"@+id/text1\"           
        android:padding=\"5dip\"

        android:text=\"Text 2 lasndklsa lkmsclslk klmsldmlk lksdl\"
        />


</RelativeLayout>
布局3的图3:(很抱歉,由于rep问题,不能发布两个以上的超链接。) 当提前不知道任一视图中的文本量时,是否可以对齐EditText视图的高度?     

解决方法

        好吧,我不得不说,这是我第一次发现TableLayout有用。请注意,文本“ LOOKS”在预览中被截断了(因为它确实很大),但是在编译和运行时,您会看到该文本是可滚动的。 TableView为您完成所有棘手的工作。我认为这对您有用。 刚刚意识到您希望文本视图也看起来相同大小-这很容易-给它们一个透明的背景并使表格的背景具有背景。 编辑-还有一件事-由于框架错误,我不得不使用它:
android:inputType=\"none\"
android:editable=\"false\"
使文本可滚动和不可编辑。另外,@ mandel的一个好处是-如果为api级以下的android设备编程,请使用\“ fill_parent \”而不是\“ match_parent \”
<TableLayout
    android:id=\"@+id/tableLayout1\"
    android:layout_width=\"fill_parent\"
    android:layout_height=\"fill_parent\"
    xmlns:android=\"http://schemas.android.com/apk/res/android\">
    <TableRow
        android:layout_height=\"fill_parent\"
        android:layout_width=\"wrap_content\"
        android:id=\"@+id/tableRow1\"
        android:gravity=\"center_vertical\">
        <EditText
            android:inputType=\"none\"
            android:editable=\"false\"
            android:text=\"I have two EditText to align. The problem is that I cannot predict which view will have more tetText to align. The problem is that I cannot predict which view will have more text and hencem  I have two EditText views whose height I wish to align. The problem is that I cannot predict which view will have more text and hence\"
            android:id=\"@+id/editText1\"
            android:layout_width=\"0dp\"
            android:layout_weight=\"1\"
            android:layout_height=\"match_parent\">
        </EditText>
        <EditText
            android:inputType=\"none\"
            android:editable=\"false\"
            android:text=\"I have two EditText views whose height I wish to alignhave more text and hence \"
            android:id=\"@+id/editText2\"
            android:layout_width=\"0dp\"
            android:layout_weight=\"1\"
            android:layout_height=\"match_parent\"></EditText>
    </TableRow>
</TableLayout>
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?