android-在一个按钮上方左右排放 textview

问题描述

在一个按钮上方左右排放 textview

relative layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
<TextView
    android:id="@+id/tv2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:layout_alignLeft="@id/button1"/>
<TextView
    android:id="@+id/tv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:layout_alignRight="@id/button1" />
</RelativeLayout>
<Button
    android:id="@+id/button1"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:text="Button" />
</LinearLayout>

我用了上面的代码没有达到下面的效果:

tv1--------------tv2
|------Button------|

想让textview1 在按钮的左上角, textview2 在按钮的右上角,如何实现呢?

解决方案

android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"

在你的两个TextView标签里分别加上这两个属性就可以了

解决方案二:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

<TextView
    android:id="@+id/tv2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:layout_alignLeft="@+id/button1"/>

<TextView
    android:id="@+id/tv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView"
    android:layout_alignRight="@+id/button1" />

<Button
    android:id="@+id/button1"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:text="Button"
    android:layout_below="@+id/tv1" />
</RelativeLayout>  

</LinearLayout>
时间: 2024-08-06 20:06:40

android-在一个按钮上方左右排放 textview的相关文章

请问鼠标悬浮在按钮上方时,如何使按钮连续变化两张图片?

问题描述 logbt.setRolloverIcon(icon3);logbt.setRolloverIcon(icon4);这里有icon3,icon4两张图片,如何做到鼠标悬浮在按钮上方时,使按钮依次变化两张图片? 问题补充:Rainbow702 写道 解决方案 为了保证线程安全,你可以使用SwingUtilities类的invokeLater()或invokeAndWait()方法:SwingUtilities.invokeLater(new Runnable() { public voi

android动态布局之动态加入TextView和ListView的方法_Android

本文实例讲述了android动态布局之动态加入TextView和ListView的方法.分享给大家供大家参考.具体实现方法如下: package org.guoshi; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.guoshi.adapter.ImageAndTextAdapter; import android.app.

Android给按钮设置背景的同时设置圆角例子

之前在做按钮的时候遇到在给按钮设置一张图片作为背景的同时还要自己定义圆角,最简单的做法就是直接切张圆角图作为按钮就可以了,但是如果不这样该怎么办呢,看代码: 先建一个圆角的shape文件: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android">     <corn

android动态布局之动态加入TextView和ListView的方法

  本文实例讲述了android动态布局之动态加入TextView和ListView的方法.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 6

实例详解Android解决按钮重复点击问题_Android

 为了防止用户或者测试MM疯狂的点击某个button,写个方法防止按钮连续点击.具体实例代码如下所示: public class BaseActivity extends Activity { protected boolean isDestroy; //防止重复点击设置的标志,涉及到点击打开其他Activity时,将该标志设置为false,在onResume事件中设置为true private boolean clickable=true; @Override protected void o

android 代码中怎么判断一个TextView有多少行?

问题描述 android 代码中怎么判断一个TextView有多少行? android 代码中怎么判断一个TextView有多少行? 解决方案 android.text.Layout包含此信息和更多final int lineCount = textView.getLayout().getLineCount(); 解决方案二: android.text.Layout包含此信息和更多final int lineCount = textView.getLayout().getLineCount();

android按钮-关于设置Android Button按钮状态(normal,focused,pressed)图片,有没有简便的方法

问题描述 关于设置Android Button按钮状态(normal,focused,pressed)图片,有没有简便的方法 Android Button按钮状态(normal,focused,pressed)的图片 大都用drawable "selector" 来实现 类似 btn_background.xml <?xml version="1.0" encoding="UTF-8"?> <selector xmlns:and

android,在一个Surfaceview上画了一个矩形,怎样再在这个矩形上画曲线?

问题描述 android,在一个Surfaceview上画了一个矩形,怎样再在这个矩形上画曲线? 要求:只画出这条曲线,曲线之外的部分不能覆盖原来的图形.如果先框出一个小矩形区域,然后再在这个区域里画曲线,结果会是整个小矩形区域都会覆盖掉原来的图形. 解决方案 mSurfaceHolder.setFormat(PixelFormat.TRANSPARENT); 将其他部分设置为透明.

easyui-关于easyUI如何在一个按钮的点击事件里面设置页面刷新的问题,

问题描述 关于easyUI如何在一个按钮的点击事件里面设置页面刷新的问题, easyUI如何在一个按钮的点击事件里面设置刷新当前页面呢,就是按钮点击后 先要向后台传值,然后还要实现刷新当前页面的功能 解决方案 在按钮的点击事件中通过ajax向后台传值,然后在回调函数中刷新当前页面.例:$("#aaaa").click(function(){ $.ajax( url:"", dataType:"json", data:{ //这里传值 }, suc