tej*_*jas 2 android relativelayout android-layout android-framelayout
下面是我设计我的xml的方法.现在,我正在尝试在下面显示的白框内插入textview.但是受到FrameLayout的限制(至少我认为是这样)我需要硬编码值以使文本视图适合中间或白盒内的某些位置.我不能为此目的使用相对或其他布局,因为我已经通过我的试验理解,因为整体是单个图像.
这是我的布局,
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:visibility="visible" android:layout_marginTop="60dip"
android:layout_gravity="center" android:id="@+id/xxx">
<ImageView android:id="@+id/calloutquizImage"
android:background="@drawable/callout" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:scaleType="fitCenter" />
<ImageView android:id="@+id/triviaImage"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="@+id/calloutquizImage" android:layout_gravity="left"
android:src="@drawable/trivia" android:background="@drawable/trivia"
android:layout_marginTop="50dip" android:layout_marginLeft="85dip"></ImageView>
<TextView android:text="TextView" android:id="@+id/triviAnswerText"
android:layout_marginTop="125dip" android:layout_marginLeft="85dip"
android:layout_gravity="left" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#000000"
android:typeface="sans"></TextView>
<ImageButton android:id="@+id/triviaanswercloseButton"
android:src="@drawable/closebtn" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@drawable/closebtn"
android:layout_marginRight="8dip" android:layout_marginTop="43dip"
android:layout_gravity="right" android:onClick="triviaanswerClose"></ImageButton>
<ImageView android:id="@+id/buttontoclose"
android:layout_gravity="left"
android:visibility="visible" android:onClick="triviaanswerClose"
android:layout_marginTop="50dip" android:layout_marginLeft="75dip"
android:layout_width="230dip" android:layout_height="170dip"></ImageView>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
因此,文本视图在各种手机中看起来处于不同的位置.
任何猜测可以为此做些什么呢?
以下是我的形象:

我认为你做的不对.如果您希望文本显示在白色框内(或者甚至调整大小,如果有许多文本适合它) - 您仍然可以避免任何布局广告只使用一个 TextView.
请查看NinePatchAndroid中的图片:http:
//developer.android.com/reference/android/graphics/NinePatch.html
http://developer.android.com/tools/help/draw9patch.html - 绘图工具
所以基本上你只需要1个textView和你的图像,正确转换为带有第二个链接的9-patch.(基本上 - 只需在图像边框上添加几个黑色像素).不只是将这个9补丁设置为textView的背景.它会将文本放在您需要的位置,如果您在9-patch中定义,则会缩小白框.
UPD:
请找到生成的截图:

正如您所看到的,textView不会处理WhiteBox"本身,填充文本并在必要时调整框大小.
以下是如何使其工作:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/first"
android:background="@drawable/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Manymanymany text
Manymanymany text
Manymanymany text
Manymanymany text
Manymanymany text
Manymanymany text" />
<TextView
android:layout_below="@+id/first"
android:background="@drawable/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not so many text" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是你的形象,转换为9patch.只需将其放在"drawable /"文件夹中即可.注意:它必须有"back.9.png"名称.

有关9patch如何工作的详细信息,您可以查看上面的链接.主要思想:通过在左边和上边框上制作黑点 - 指定图像必须放大时图像的哪个部分将被拉伸.通过在右侧/底侧制作点,您可以告诉View放置内容的位置.在我们的例子中,content是TextView的文本.
希望它有所帮助,祝你好运
| 归档时间: |
|
| 查看次数: |
10708 次 |
| 最近记录: |