2015-06-19 259 views
-1

我目前正在尝试创建一个列表视图,它将显示关于帖子的详细信息。为此,我创建了用于设计列表项目的xml文件。设计布局android

enter image description here

这是最后一眼我要为我的活动。到目前为止,我已经成功地处理了圆角,图像按钮和文本,但我尝试了一段时间来处理文本框的左侧。我希望它有一个尖锐的提示。但我仍然无法处理它。

我将添加xml文件来显示我做了什么。

**This is the xml file for the list item** 

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="300dp" 
    android:layout_height="160dp"> 

    <LinearLayout android:id="@+id/desclayout" 
     android:layout_width="240dp" 
     android:layout_height="140dp" 
     android:background="@drawable/layout_my_posts_selector" 
     android:layout_marginRight="5dp"> 

     <TextView 
      android:id="@+id/myPostDescription" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:gravity="left" 
      android:maxLength="120" 
      android:hint="@string/description" 
      android:inputType="textMultiLine" 
      android:lines="4" 
      android:maxLines="5" 
      android:paddingBottom="8dp" 
      android:textColorHint="#f7941e" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 
      android:paddingTop="8dp" 
      android:textColor="#6d6e71" 
      android:scrollbars="vertical" 
      android:textSize="14sp"> 
     </TextView> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_toRightOf="@+id/desclayout" 
     android:background="@drawable/description_layout_my_posts_selector" 
     android:orientation="vertical" 
     android:paddingLeft="7dp" 
     android:layout_height="140dp"> 

     <ImageButton 
      android:id="@+id/acceptMyPostBtn" 
      android:layout_width="40dp" 
      android:background="@drawable/my_posts_button_selector" 
      android:layout_marginTop="5dp" 
      android:layout_height="40dp" 
      android:src="@drawable/v"/> 

     <ImageButton 
      android:id="@+id/closeMyPostBtn" 
      android:layout_width="40dp" 
      android:background="@drawable/my_posts_button_selector" 
      android:layout_below="@id/acceptMyPostBtn" 
      android:layout_height="40dp" 
      android:layout_marginTop="5dp" 
      android:src="@drawable/x"/> 

     <ImageButton 
      android:id="@+id/showOnMapMyPost" 
      android:layout_width="40dp" 
      android:src="@drawable/location" 
      android:background="@drawable/my_posts_button_selector" 
      android:layout_marginTop="5dp" 
      android:layout_height="40dp"/> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_below="@+id/desclayout" 
     android:paddingLeft="6dp" 
     android:background="#2d2d2d" 
     android:layout_height="20dp"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:textColor="@android:color/background_light" 
      android:text="Finished at 19/01/2013 13:55" 
      android:layout_height="fill_parent" /> 
    </LinearLayout> 
</RelativeLayout> 

layout_my_posts_selector

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 

    <solid android:color="#f1f1f2"/> 

    <stroke android:width="3dp" android:color="#2d2d2d" /> 

    <corners android:topLeftRadius="7dp" android:bottomLeftRadius="7dp"/> 

    <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> 
</shape> 

description_layout_my_posts_selector

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#e7e8ea"/> 
    <stroke android:width="3dp" android:color="#2d2d2d" /> 
    <corners android:topRightRadius="7dp" android:bottomRightRadius="7dp"/> 
    <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> 
</shape> 

这就是它现在的样子enter image description here

如果你可以请指导我如何处理锋利的提示,我会感激!

由于提前, 伊甸园

回答

0

可以绘制而不是背景。 因此,您可以使用photoshop或paint.net中左侧的“尖端”设计背景图像,并设置属性android:[email protected]/background_design,其中“背景设计”是您的设计可绘制文件的名称。

编程它将花费更多的资源来渲染设计。在列表视图中使用不是一个好习惯。为获得最佳性能,请使用静态布局的drawable。

-1

Use This 9 Patch Image您可以在使用一个单独的背景XML文件是一个好主意,我会建议你使用使用9补丁作为background.Create一个here

+0

你的答案是确定的,但你应该给一个理由,为什么不在XML或编程水平,不得不提到的任何可能性是存在与否。 – Boopathi

+0

如果您准备好编码,一切皆有可能。 我向你展示了实现它的最简单方法。 检查[this](https://github.com/madhur/android-chat-starter)项目。 –

0

好了,我不明白为什么我的帖子已经得到-1,

但无论如何我会后我选择了做它的方式。命名

我已经装箱的XML文件:三角

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <rotate 
      android:fromDegrees="45" 
      android:pivotX="87%" 
      android:pivotY="115%" 
      android:toDegrees="45"> 
      <shape android:shape="rectangle"> 
       <solid android:color="#f1f1f2"/> 
      </shape> 
     </rotate> 
    </item> 
</layer-list> 

在这之后我加入线性布局,以我的list_item_xml与 三角形XML的背景。

感谢您的帮助,有一个愉快的一天