简体   繁体   English

消息传递应用程序Android XML的布局问题

[英]Layout issue for messaging app Android XML

I'm trying to create a messaging app in android and have created a custom list adapter that displays the message text and then the date as well. 我正在尝试在android中创建一个消息传递应用程序,并创建了一个自定义列表适配器,该适配器显示消息文本以及日期。 I have got them both displaying, now want them to be able to be displayed in a certain way. 我同时显示了它们,现在希望它们能够以某种方式显示。 I want to be able to have sent messages on one side of the screen but received messages on the other, with the date appearing below/to the side of the message text 我希望能够在屏幕的一侧发送消息,而在另一侧接收消息,并且日期显示在消息文本的下方/侧面

This is the custom xml I have used for each item on the list, any ideas on how to make them wrap appropriately and move to sides of the screen would be appreciated! 这是我用于列表中每个项目的自定义xml,任何有关如何适当包装它们并移至屏幕两侧的想法都将不胜感激!

(Note: I've tried using LinearLayouts with weights and RelativeLayouts with android:layout_alignParentRight and things, but couldn't get it exactly how I wanted it so thought I'd ask here!) (注意:我尝试将LinearLayouts与权重结合使用,将RelativeLayouts与android:layout_alignParentRight和其他东西结合使用,但由于无法获得所需的确切信息,所以我想在这里问!)

(Don't think other code snippets are needed but can provide if wanted!) (不要认为需要其他代码段,但是可以根据需要提供!)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
<TextView android:id="@+id/msgTxt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@android:color/black"
    android:paddingRight="2dp"
    android:textStyle="bold"
    android:textSize="15sp" />

<TextView android:id="@+id/msgDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     />
</LinearLayout>

Cheers 干杯

I've tried using LinearLayouts with weights 我试过使用权重的LinearLayouts

Whats wrong with that? 怎么了 android:layout_weight="0.4"

try to use not 'fill_parent', use 'match_parent'; 尝试不使用“ fill_parent”,使用“ match_parent”;

also, replace this 另外,替换这个

android:textSize="15sp"

to this: 对此:

android:textAppearance="?android:attr/textAppearanceMedium"

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

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