TextView和ImageView的Android布局问题
我刚开始为Android编写一个新的应用程序,并且偶然发出警告。TextView和ImageView的Android布局问题
这个标签及其子可以通过一个和一个化合物绘制
代替我的另一个问题是放置在右侧的图像。我怎样才能做到这一点,而不会有layout_wight的麻烦?请参阅图像([2],黄色和绿色突出显示)。
我想遵循android design guide并防止警告。那么我该如何解决这个问题?实际我的代码如下所示:
<LinearLayout
android:id="@+id/mainTitleLinearLayout"
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/mainTitleImageView"
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="8dp"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/app_name"/>
<TextView
android:id="@+id/mainTitleTextView"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:gravity="left|center_vertical"
android:paddingBottom="4dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="4dp"
android:text="@string/app_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="2dp" android:background="#0099CC"></LinearLayout>
难道你们知道用于构建自定义组件,所以我不要再出现此错误和/或解决布局问题的一些好的教程?
1http://developer.android.com/design/style/metrics-grids.html
这不是一个错误,只是一个信息(或警告),有一种更有效的方式来实现由图像和文本视图组成的布局中的一行。你可以这样做:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/error_tab"
/>
drawableLeft属性将给定的drawable添加到文本视图的左侧。以类似的方式,您可以将图像放在右侧。
但是,您将无法微调图像的位置。文本视图。
我写了一个blog post about compound drawables它可以帮助您解决问题。
嗨马克,我已经阅读过你的博客文章,但无法解决我的摆放问题,斯蒂芬指出。不过谢谢你的帮助。 – burnersk 2012-02-01 11:59:05
你是一个程序员,你不必担心警告...... :) – himanshu 2012-02-01 11:42:41
@himanshu:忽略警告不是一个好习惯:D @burnersk:你可以用单个'TextView'和复合Drawables来代替这个布局。 – 2012-02-01 11:47:59
是的,同意你@AdilSoomro – Lucifer 2012-02-01 11:49:12