知识点
相关文章
更多最近更新
更多[Android]用LinearLayout 实现类微信消息列表项
2019-03-02 00:06|来源: 网路
实现效果:
微信参照界面:
一个关键点: "早晚报"与"下午19:05"之间要用空白TextView隔开,来造成一个靠左,一个靠右的效果
LinearLayout Item 结构如下
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:id="@+id/imageview_selector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/green"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/nickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="早晚报"/>
<TextView
android:id="@+id/nickname22"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:id="@+id/rightnickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下午19:05"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/rightnickname2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="晚报:北京10日出租车涨价"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
转自:http://my.oschina.net/u/996206/blog/136095
相关问答
更多-
您已将text_container的宽度设置为match_parent 。 您应该设置为0dp并为此元素添加layout_weigh您正在使用错误的LayoutParams类。 使用LinearLayout.LayoutParams而不是ActionBar.LayoutParams 。 You are using the wrong LayoutParams class. Use LinearLayout.LayoutParams instead of ActionBar.LayoutParams.解决了我只需要为FrameLayout更改我的LinearLayout! 谢谢大家! Solved I just need to change my LinearLayout for FrameLayout! Thanks for all!问题解决了。 正如用户207在其中一个注释中给出的,来自另一个stackoverflow问题的正确解决方案是: 这是XML:尝试将android:animateLayoutChanges="true"到线性布局中 try adding android:animateLayoutChanges="true" to the linear layout我不确定为什么你需要3个嵌套的线性布局,我认为这应该完成你想要做的事情。尝试这个..给android:layout_weight="0.5"水平两个布局
在android中扩展LinearLayout而不是Activity(Extend a LinearLayout instead of Activity in android)[2023-08-17]
创建一个android项目时,一个活动是必要的。 每个活动本身都使用setContentView()来托管布局。 如果可以在单独的类中扩展LinearLayout,则将其设置为单独活动内的主内容视图: LinearLayout mainLin = (LinearLayout)findViewById(R.id.main); MyLinearLayout m = new MyLinearLayout(); 然后,您可以将布局添加到主布局: setContentView(R.id.main); // in ...这两个问题源于对GridBagLayout的错误理解。 更多的阅读和实验应该有所帮助)回答手头的问题: 1)这里的问题是你想要一个GridBagLayout,而是添加2个独立的面板。 结果:顶部网格袋中的列独立于底部网格袋中的列。 要纠正这个问题,您可以尝试两件事: 将两个标签和两个文本字段添加到单个GridBag面板。 这样,列将对齐。 为标签设置最小和首选大小,使其宽度匹配并将其权重x设置为0(文本字段的权重x为非零)。 这样你就可以让GridBags为标签和文本字段分配相同的空间。 第一种方法是首选方 ...您必须为您的属性定义正确的名称空间。 看这篇文章 。 You must define a correct namespace for your attributes. See this post.