我正在编写一个Android应用程序,但遇到了奇怪的事情。即,这是我图标的可见性。它应该在屏幕的右侧。
当我将其放在左侧时,就可以了,它是这样可见的:
但是当我说对了,它看起来像这样:
我的代码如下所示:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/space_medium" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp" >
<TextView
android:id="@+id/_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginLeft="10dp"
android:text="@string/title"
android:textColor="#666666"
android:textSize="20sp"/>
<ImageView
android:id="@+id/image"
android:layout_width="60dp"
android:layout_height="60dp"
android:gravity="top"
android:alpha=".50"
android:src="@drawable/paprika" />
</LinearLayout>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:text="@string/description"
android:textColor="#666666" />
<Button
android:id="@+id/_view"
android:layout_width="fill_parent"
android:layout_height="@dimen/button"
android:layout_marginBottom="15dp"
android:layout_marginTop="@dimen/space_small"
android:background="@drawable/rect_rounded_light_blue"
android:text="Button"
android:textColor="#fff" />
</LinearLayout>
</ScrollView>
一些注意事项:
您是否尝试过将图像不放置在ImageView中,而是直接放置在TextView中(较少的Views =更好的性能)?称为复合可绘制对象:
android:drawableTop | Left | Right | Bottom =“ @ drawable / your_image”
这也将防止Z索引重叠。
因此,这就是我将其组合在一起的方式:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:fillViewport="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/space_medium"
>
<TextView
android:id="@+id/_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginLeft="10dp"
android:drawableRight="@drawable/paprika"
android:drawablePadding="8dp"
android:text="@string/title"
android:textColor="#667"
android:textSize="20sp"
/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/_title"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:text="@string/description"
android:textColor="#667"
/>
<Button
android:id="@+id/_view"
android:layout_width="fill_parent"
android:layout_height="@dimen/button"
android:layout_below="@id/description"
android:layout_marginBottom="15dp"
android:layout_marginTop="@dimen/space_small"
android:background="@drawable/rect_rounded_light_blue"
android:text="Button"
android:textColor="#fff"
/>
</RelativeLayout>
</ScrollView>
要以编程方式设置复合可绘制对象(一旦您拥有对TextView的引用),只需使用该setCompoundDrawablesWithIntrinsicBounds()
方法来分配一个或多个复合图像,如此处所述:http : //developer.android.com/reference/android/widget/TextView .html#setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句