有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java文本视图未显示在linearLayout中

为什么id为textView1和textView2的textview没有显示,但其他所有内容都显示出来了

我试着添加

安卓:layout_alignLeft="@+id/bus_data"
安卓:layout_below="@+id/bus_data"

但它仍然没有出现。我不知道xml有什么问题

以下是xml代码:

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:paddingBottom="@dimen/activity_vertical_margin"
安卓:paddingLeft="@dimen/activity_horizontal_margin"
安卓:paddingRight="@dimen/activity_horizontal_margin"
安卓:paddingTop="@dimen/activity_horizontal_margin"
tools:context=".MainActivity"
安卓:background="#545454" >
<LinearLayout          
    安卓:layout_width="fill_parent"
    安卓:layout_height="wrap_content"
    安卓:orientation="horizontal" 
    安卓:id="@+id/search_result_box"
    安卓:background="@drawable/search_item_selector_stlye">      
    <LinearLayout          
        安卓:layout_width="fill_parent"
        安卓:layout_height="wrap_content"
        安卓:orientation="horizontal" 
        安卓:id="@+id/bus_data"
        安卓:background="@drawable/search_item_selector_stlye">

                <LinearLayout 
                安卓:layout_width="wrap_content"
                安卓:layout_height="wrap_content"
                安卓:orientation="vertical">

                    <TextView   安卓:id="@+id/stop_code_string"
                                安卓:text="@string/stop_code_string"
                                安卓:layout_width="wrap_content"
                                安卓:layout_height="wrap_content"
                                安卓:textColor="#2a2a2a"
                                安卓:textSize="10sp"
                                安卓:layout_gravity="center"
                                安卓:gravity="center"        />
                    <TextView   安卓:id="@+id/stop_code"
                                安卓:layout_width="wrap_content"
                                安卓:layout_height="wrap_content"
                                安卓:text="@string/stop_code_string"                 
                                安卓:padding="20dip"
                                安卓:textColor="#2a2a2a"
                                安卓:textSize="16sp"
                                安卓:textStyle="bold" 
                                安卓:gravity="center"
                                安卓:background="@drawable/right_border_line_textview"
                    />

                </LinearLayout>

                <View
                安卓:layout_width="1dip"
                安卓:layout_height="fill_parent"
                安卓:background="#bdbdbd"
            />

                 <LinearLayout 
                安卓:layout_width="wrap_content"
                安卓:layout_height="wrap_content"
                安卓:orientation="vertical">

                     <TextView  安卓:id="@+id/stop_name_String"
                                安卓:text="@string/stop_name_string"
                                安卓:layout_width="wrap_content"
                                安卓:layout_height="wrap_content"
                                安卓:textColor="#2a2a2a"
                                安卓:textSize="10sp"
                                安卓:gravity="center"
                                安卓:paddingLeft="5dp"
                    />
                    <TextView   安卓:id="@+id/stop_name"
                                安卓:layout_width="wrap_content"
                                安卓:layout_height="wrap_content"
                                安卓:text="@string/stop_name_string"
                                安卓:paddingLeft="20dp"
                                安卓:paddingTop="10dp"
                                安卓:textColor="#2a2a2a"
                                安卓:textSize="16sp"
                                安卓:textStyle="bold"
                        />
                </LinearLayout>


    </LinearLayout>
    <LinearLayout 
        安卓:layout_width="fill_parent"
        安卓:layout_height="wrap_content"
        安卓:orientation="vertical" 
        安卓:id="@+id/search_result_data_box"
        安卓:background="@drawable/search_item_selector_stlye">

        <TextView
            安卓:id="@+id/textView1"
            安卓:layout_width="wrap_content"
            安卓:layout_height="wrap_content"
            安卓:layout_alignLeft="@+id/bus_data"
            安卓:layout_below="@+id/bus_data"
            安卓:text="asdasdasdasdas" />
        <TextView
            安卓:id="@+id/textView2"
            安卓:layout_width="wrap_content"
            安卓:layout_height="wrap_content"
            安卓:layout_alignLeft="@+id/bus_data"
            安卓:layout_below="@+id/bus_data"
            安卓:text="asdasdasdasdas" />

    </LinearLayout>
</LinearLayout>


共 (2) 个答案

  1. # 1 楼答案

    这两个TextView似乎都引用bus_data作为View的id,它们需要在下方和左侧对齐,以进行编辑

    然而,他们通过添加一个新id(+id)来引用它

    他们可能只引用现有id,而不尝试创建新id

    另请参见:thisSO thread以了解有关android:id属性的更多信息

  2. # 2 楼答案

    这些文本视图位于线性布局中。在RelartivelLayout中只有belowleft。 请为您的家长线性布局提供以下参数和左参数

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:id="@+id/search_result_data_box"
        android:layout_alignLeft="@+id/bus_data"
        android:layout_below="@+id/bus_data"
        android:background="@drawable/search_item_selector_stlye">
    

    我看到bus_data也在线性布局中,所以您计划做的事情不起作用。尝试其他方法,或者发布一张你想要实现的布局的图片