我正在尝试创建一个向用户显示一些数据的活动.数据可以分为"单词",每个单词都是一个小部件,"单词"序列将形成数据("句子"?),包含单词的ViewGroup小部件.由于"句子"中所有"单词"所需的空间将超过显示器上的可用水平空间,我想像正常的文本一样包装这些"句子".
以下代码:
public class WrapTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout l = new LinearLayout(this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams mlp = new LinearLayout.LayoutParams(
new ViewGroup.MarginLayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
mlp.setMargins(0, 0, 2, 0);
for (int i = 0; i < 10; i++) {
TextView t = new TextView(this);
t.setText("Hello");
t.setBackgroundColor(Color.RED);
t.setSingleLine(true);
l.addView(t, mlp);
}
setContentView(l, lp);
}
}
Run Code Online (Sandbox Code Playgroud)
产生类似左图的东西,但我想要一个布局呈现相同的小部件,如右图所示.

是否有布局或布局和参数的组合,还是我必须为此实现自己的ViewGroup?
有没有办法在水平线性布局中包装图像按钮?或者还有其他方法可以做以下事情吗?
我有六个图像按钮.假设这些按钮出现在中等分辨率设备中,如下所示:
Image button 1 | Image button 2 | Image button 3 | (1st row)
Image button 4 | Image button 5 | Image button 6 | (2nd row)
Run Code Online (Sandbox Code Playgroud)
我希望这些按钮出现在平板电脑或任何高分辨率设备中,如下所示:
Image button 1 | Image button 2 | Image button 3 | Image button 4 | (1st row)
Image button 5 | Image button 6 | (2nd row)
Run Code Online (Sandbox Code Playgroud)
或者像这样:
Image button 1 | Image button 2 | Image button 3 | Image button 4 | Image button 5 | …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个UI,在其中我具有在XML中定义的线性布局。
根据用户的输入,我需要向此线性布局添加一些TextView。我能够做到这一点。
我的实际问题是,当我拥有更多的文本视图时,它们彼此并排堆叠,并且某些文本视图的文本被隐藏或垂直拉伸,如下图所示。

我想使用线性布局的整个宽度,如果文本视图不能容纳在此行中,则应将其放在新行中或第一个文本视图的下面。我希望显示如下。

以下是我在XML中的线性布局配置:
<RelativeLayout
android:id="@+id/RL1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingBottom="5dip"
android:paddingTop="5dip" >
<TextView
android:id="@+id/text1"
android:layout_width="85dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="left"
android:text="Lable 1"
android:textColor="#999999" />
<LinearLayout
android:id="@+id/LL1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/button1"
android:layout_toRightOf="@+id/text1"
android:gravity="left|center_vertical"
android:orientation="horizontal"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:paddingTop="3dip" >
</LinearLayout>
<Button
android:id="@+id/button1"
android:layout_width="30dip"
android:layout_height="30dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginTop="2dip"
android:background="@drawable/plus"
android:clickable="true"
android:focusable="true"
android:paddingTop="5dip" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我如何在Java代码中重新对齐相同的内容。
android alignment textview android-layout android-linearlayout
对于我的应用程序,我正在尝试在文章中列出标签,但我无法找到可以实现此目的的Android布局.
基本上,我有一个字符串数组,其中包含1到5个元素.我希望能够以一种交错的方式列出它们.类似于Horizontal LinearLayout将执行的操作,但如果下一个视图太大则会转到下一行.我必须以编程方式执行此操作,而不使用ListView/GridView,因为它位于ScrollView中.
有没有办法实现这个目标?
这是我的意思的编辑图像... http://i.stack.imgur.com/Hhpry.png

java android android-layout android-linearlayout staggered-gridview
嗨,我想制作一个回收器视图,以将项目水平放置与屏幕适合的数量一样多,但使用垂直滚动,例如此图像
我尝试使用StaggeredGridLayoutManager但它必须指定列数希望列作为屏幕大小任何帮助都会很好