【问题标题】:Android Relative Layout alignmentAndroid 相对布局对齐
【发布时间】:2014-09-11 06:45:33
【问题描述】:

我有一个表格。其中有几行。每行有两个并排的文本视图。左边的文本视图是静态的,右边的文本视图是动态的。基于右文本视图的文本(可能是任意数量的行),下一行的原点必须取决于如下所示。我正在使用 relativelayout 并用 xml 编写。我该怎么做。

注意:由于某些限制,我不想使用网格或表格布局。

【问题讨论】:

  • 你检查过我的答案吗
  • @kaushik 我知道,但我有很多领域,我对这种方式不感兴趣

标签: android android-layout user-interface textview android-relativelayout


【解决方案1】:

RelativeLayout.LayoutParams 参数 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 参数.addRule(xxxxx);

【讨论】:

  • 我应该添加哪条规则?
  • 1. params.addRule(RelativeLayout.RIGHT_OF, left_top_view_id); 2. params.addRule(RelativeLayout.RIGHT_OF, left_bottom_view_id); params.addRule(RelativeLayout.BOTTOM_OF, right_top_view_id);
【解决方案2】:

修复左侧 textview 静态并从 java 代码中绘制剩余项目。

【讨论】:

  • 如果您没有使用硬编码值限制宽度和高度,您可以使用 xml,否则使用 java
【解决方案3】:

你可以试试这个方法

<RelativeLayout 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" >

    <LinearLayout
        android:id="@+id/firstLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:singleLine="true"
            android:text="Static Text 1"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:singleLine="false"
            android:text="Multiple line\nDynamic text 1"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/secondLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/firstLinearLayout"
        android:layout_marginTop="8dp" >

        <TextView
            android:id="@+id/textView3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:singleLine="true"
            android:text="Static Text 2"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:singleLine="false"
            android:text="Multiple line\nDynamic text 2"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>

</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    相关资源
    最近更新 更多