永发信息网

android如何实现EditText中添加ImgeButton

答案:3  悬赏:70  手机版
解决时间 2021-01-26 18:08
  • 提问者网友:城市野鹿
  • 2021-01-26 10:42
android如何实现EditText中添加ImgeButton
最佳答案
  • 五星知识达人网友:刀戟声无边
  • 2021-01-26 11:45


这上面的是实现效果:

现在来分析下:
EditText是Android中用来输入内容的控件,要在其内部放置ImgeButton
其实就是布局的问题了
应该使用相对布局RelativeLayout ,因为使用RelativeLayout 布局可以根据android:layout_alignRight="@id/"来控制组件与其他组件之间的关系是怎样的,就是组件与组件之间的相对位置
RelativeLayout子控件的一些属性:

     //相对于同级控件对齐方式


android:layout_alignBaseline将该控件的baseline与给定ID的baseline对齐;
android:layout_alignTop 将该控件的顶部边缘与给定ID的顶部边缘对齐;
android:layout_alignBottom将该控件的底部边缘与给定ID的底部边缘对齐;
android:layout_alignLeft       将该控件的左边缘与给定ID的左边缘对齐;
android:layout_alignRight     将该控件的右边缘与给定ID的右边缘对齐;
// 相对于父组件对齐方式
android:layout_alignParentTop      如果为true,将该控件的顶部与其父控件的顶部对齐;
android:layout_alignParentBottom 如果为true,将该控件的底部与其父控件的底部对齐;
android:layout_alignParentLeft      如果为true,将该控件的左部与其父控件的左部对齐;
android:layout_alignParentRight    如果为true,将该控件的右部与其父控件的右部对齐;
// 居中
android:layout_centerHorizontal 如果为true,将该控件的置于水平居中; 
android:layout_centerVertical     如果为true,将该控件的置于垂直居中; 
android:layout_centerInParent   如果为true,将该控件的置于父控件的中央; 
// 控件离上下左右的像素距离
android:layout_marginTop      上偏移的值; 
android:layout_marginBottom 下偏移的值; 
android:layout_marginLeft 左偏移的值; 
android:layout_marginRight 右偏移的值;
//控件相对同级控件的位置
android:layout_toLeftOf在ID控件的左边
android:layout_toRightOf在ID控件的右边
android:layout_below在ID控件的下边
android:layout_above在ID控件的上边
        android:layout_marginTop="30dp"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       >
                  android:id="@+id/login_password"
           android:layout_width="fill_parent"
           android:layout_height="40dp"
           android:hint="请输入密码"
           android:password="true"
           android:textAppearance="?android:attr/textAppearanceMedium"
           android:singleLine="true" 
           android:ellipsize="end"
           android:paddingRight="5dp"/>
                  android:id="@+id/see_password"
           android:layout_width="40dp"
           android:layout_height="25dp"          
           android:background="@drawable/eyes"
           android:layout_margin="10dp"
           android:layout_alignRight="@id/login_password"
           />
   
全部回答
  • 1楼网友:慢性怪人
  • 2021-01-26 13:46
可以用布局直接实现,同样的功能,比如EditText后面跟着ImageButton,但是如果非要实现那种 EditText中有ImageButton的话,那么自己写一个类,继承EditText,然后new ImageButton(),然后在布局中应用就行了。
  • 2楼网友:慢性怪人
  • 2021-01-26 13:19
感觉用布局就能实现,用RelativeLayout 布局,EditText和ImageButton 都相对于同一view左对齐,然后ImageButton 的左边留出一定的空隙就可了。
希望有帮助。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯