Страница 1 из 1

add RelativeLayout to LinearLayout програмно??

Добавлено: 16 ноя 2012, 19:33
JDev
Познаю основы разметки. ))
Ну тут я сложил руки, не вижу, что не так.
У меня небольшой чатик, и хочу, чтоб сообщения выравнивались слева и справа.
У RelativeLayout есть свойства. android:layout_alignParentRight="true"
Но дело в том, что он не отображается на экране. (

Добавляю

Код: Выделить всё

	private void addMessageToStage(Message message) {
		LinearLayout scrollChatMessagesOutput = (LinearLayout) findViewById(R.id.chatMessagesOutput);

		LayoutInflater ltInflater = getLayoutInflater();
		View view = ltInflater.inflate(R.layout.chat_message, null, false);
		TextView messageTextView = (TextView) view.findViewById(R.id.inputMessageTextView);
		messageTextView.setText(message.getMessage());
		scrollChatMessagesOutput.addView(view);
	}

Код: Выделить всё

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <ScrollView
                android:id="@+id/scrollViewChatMessagesOutput"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:weightSum="1.0" >

                <LinearLayout
                    android:id="@+id/chatMessagesOutput"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical" >
                </LinearLayout>
            </ScrollView>
        </LinearLayout>
    </TableRow>
и вот так вот выглядит мое сообщение

Код: Выделить всё

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <ScrollView
                android:id="@+id/scrollViewChatMessagesOutput"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:weightSum="1.0" >

                <LinearLayout
                    android:id="@+id/chatMessagesOutput"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical" >
                </LinearLayout>
            </ScrollView>
        </LinearLayout>
    </TableRow>

что странно, если в лейоуте(в этом последнем) стоит LinearLayout вместо RelativeLayout то все работает. Только ж у LinearLayout нет таких свойств..

Спасибо за подсказку.

Re: add RelativeLayout to LinearLayout програмно??

Добавлено: 19 ноя 2012, 17:11
damager82
У вас два одинаковых фрагмента разметки приведены. RelativeLayout на них нет.