【问题标题】:Layout issue for messaging app Android XML消息传递应用程序 Android XML 的布局问题
【发布时间】:2013-10-21 11:54:12
【问题描述】:

我正在尝试在 android 中创建一个消息传递应用程序,并创建了一个自定义列表适配器,该适配器显示消息文本,然后显示日期。我已经让它们都显示了,现在希望它们能够以某种方式显示。我希望能够在屏幕的一侧发送消息,但在另一侧接收消息,日期显示在消息文本的下方/一侧

这是我为列表中的每个项目使用的自定义 xml,任何关于如何使它们正确包装并移动到屏幕两侧的想法将不胜感激!

(注意:我尝试过使用带权重的 LinearLayouts 和带 android:layout_alignParentRight 的 RelativeLayouts 等,但无法完全按照我的意愿使用它,所以我想在这里问一下!)

(认为不需要其他代码sn-ps,但如果需要可以提供!)

<?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>

干杯

【问题讨论】:

  • 找出发送和接收的项目,然后制作固定宽度的文本视图(比如100dp)并根据发送/接收的消息左/右对齐。
  • RelativeLayout 非常适合这个,使用 alignParentLeft 或 alightParentRight。您可以根据需要在代码中进行设置。

标签: java android xml android-layout layout


【解决方案1】:

我尝试过使用带权重的 LinearLayouts

这有什么问题吗? android:layout_weight="0.4"

尽量不要使用'fill_parent',使用'match_parent';

另外,替换这个

android:textSize="15sp"

对此:

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

【讨论】:

  • 啊,好的,谢谢,将进行这些更改。但是我对 layout_weight 的问题是它只是占据了屏幕的一部分(0.4 / 重量总和),而不是左右移动,无论如何谢谢
猜你喜欢
  • 1970-01-01
  • 2021-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多