您的位置:首页 > 移动开发 > Android开发

android学习1——制作title,2条横线夹住标题,切换语言改变使得title自适应d

2018-03-13 23:53 369 查看
使用场景:
    当我们使用Android开发界面时,通常我们要对界面设置一个标题。但是,随着产品中语言的切换会导致字符串的长度发生改变,从而使得界面发生混乱。
    下面的title的设置写在布局文件中,可以随着语言的切换,使得字符串长度发生变化,而不会使得界面发生混乱。
备注:当*.xml的主布局为<LinearLayout>时,需要将<LinearLayout 中的android:layout_centerHorizontal="true" 修改为android:layout_gravity="center_horizontal"
<RelativeLayout>
<LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="145dip"
      >
      
    <RelativeLayout
      android:layout_width="870dip"
      android:layout_height="wrap_content"
      android:layout_gravity="center_horizontal"
        >
        <TextView 
           android:id="@+id/textview_title" 
           android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true" 
      android:text="@string/hello_world"
      android:textSize="28sp"
            />
        <View
            android:background="#686868"
            android:layout_width="wrap_content"
      android:layout_height="0.5dip"
      android:layout_centerHorizontal="true"
      android:layout_toLeftOf="@id/textview_title"
      android:layout_marginRight="10dip"
            />
            <View
           android:background="#686868"
           android:layout_width="wrap_content"
      android:layout_height="0.5dip"
      android:layout_centerHorizontal="true"
      android:layout_toRightOf="@id/textview_title"
      android:layout_marginLeft="10dip"
            />
        </RelativeLayout>
   </LinearLayout>
 </RelativeLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: