实现了左侧div宽度固定,右侧根据左侧宽度自适应屏幕宽度的功能,代码如下:
<!doctype html>
<html>
<head>
<meta charset=”utf-8″>
<title>左侧div宽度固定,右侧根据左侧宽度自适应屏幕宽度</title>
<style type=”text/css”>
* {font-size:12px;margin:0px;padding:0px;}
a {text-decoration:none;color:#000;}
a img {border:none;}
.cl {clear:both;}
div.boxall {position:relative;padding-left:180px;}
div.left {width:180px;margin-left:-180px;float:left;height:300px;background:blue;}
div.right {width:100%;float:left;height:300px;background:red;}
</style>
</head>
<body>
<div class=”boxall”>
<div class=”left”>
左侧内容,左侧固定宽度
</div>
<div class=”right”>
右侧内容,右侧根据左侧宽度自适应屏幕宽度
</div>
</div>
</body>
</html>
要实现如下效果
1,一行左侧显示一段文字,右侧显示一段文字
2,左侧背景色为黄色,右侧背景色为绿色
3,右侧宽度根据内容文字自动
4,左侧宽度根据右侧宽度自动
效果如图(2个图片):


这样在android安卓下如何实现呢?很难?公司程序说实现不了,自己动手,代码如下:
<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”horizontal”
android:paddingTop=”50dp” >
<TextView
android:id=”@+id/text1″
android:layout_width=”match_parent”
android:layout_height=”30dp”
android:layout_toLeftOf=”@id/text2″
android:background=”#ff6600″
android:ellipsize=”end”
android:gravity=”center”
android:paddingLeft=”6dp”
android:paddingRight=”6dp”
android:singleLine=”true”
android:text=”毛主席万岁,毛主席万岁,毛主席万岁,毛主席万岁,毛主席万岁,毛主席万岁,毛主席万岁” >
</TextView>
<TextView
android:id=”@+id/text2″
android:layout_width=”wrap_content”
android:layout_height=”30dp”
android:layout_alignParentRight=”true”
android:background=”#00ff00″
android:gravity=”center”
android:paddingLeft=”6dp”
android:paddingRight=”6dp”
android:text=”30/30″ >
</TextView>
</RelativeLayout>
近期评论