我怎么能窝相对布局内的线性布局才达到所期望的UI体验? [英] How can I nest a linear layout inside a relative layout to achive the desired UI experience?

查看:131
本文介绍了我怎么能窝相对布局内的线性布局才达到所期望的UI体验?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经浪费了足够的时间试图弄清楚这个问题了自己,所以张贴的问题在这里,看看是否有人能帮助我。我想(如果从我的iOS应用程序截图)得到下面看一下我的应用程序的Andr​​oid版本。

I have wasted enough time trying to figure this issue out myself, so posting the question here to see if someone can help me out. I am trying to get the following look (screenshot if from my ios app) on the android version of my app.

我作为Android的如下定义我的布局文件:

I have defined my layout file as follows in android:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <EditText
        android:id="@+id/postTextTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/shareLILayout"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:ems="10"
        android:gravity="top|left|start"
        android:inputType="textMultiLine" >

        <requestFocus />
    </EditText>

    <LinearLayout 
        android:id="@+id/shareLILayout"
        android:layout_alignParentBottom="true"
        android:background="#999999"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:orientation="horizontal" >

        <ImageButton
            android:contentDescription="@string/li_btn_desc"
            android:id="@+id/postToLIButton"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginRight="5dp"
            android:layout_marginBottom="5dp"
            android:background="@android:color/transparent"
            android:src="@drawable/linkedin_switch_off" />

        <TextView
            android:id="@+id/postToLITextView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="@string/share_on_linkedin"
            android:layout_gravity="center_vertical"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="14sp" />

    </LinearLayout>
</RelativeLayout>

如果我换我上面的ImageButton和TextView的,我的应用程序只是一个RuntimeException崩溃!另外,我不能够居中文本,以便其对齐按钮的中心。我必须做一些错误的,我已经试过两个SO和谷歌搜索。我想AP preciated任何指针朝着正确的方向。

If I swap my ImageButton and TextView above, my app just crashed with a RuntimeException!! Also I am not able to center the text so that its aligned to the center of the button. I must be doing something wrong and I have tried searching on both SO and google. I would appreciated any pointers in the right direction.

- 苏

推荐答案

只需简单更换的的ImageButton 的TextView 序。你的运行时错误或者是不相关的或者是由需求造成的,你需要重新部署(有时资源ID得到质朴)之前清理项目。还可以使用安卓重力=center_vertical的TextView 正确居中

Simply swap the ImageButton and TextView order. Your runtime error is either unrelated or is caused by the need to clean your project before you need to redeploy it (sometimes resource IDs get funky). Also use android:gravity="center_vertical" for you TextView to center it properly

这篇关于我怎么能窝相对布局内的线性布局才达到所期望的UI体验?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆