我想知道是否有可能将每个单独RadioButton的组合在一起,RadioGroup
保持相同的结构.我的结构看起来像这样:
如你所见,现在每个人RadioButton都是不同的孩子LinearLayout.我尝试使用下面的结构,但它不起作用:
我在我的应用程序中有这个代码:
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
Run Code Online (Sandbox Code Playgroud)
我只想将LinearLayout的方向设置为垂直.XML中的等价物是:
android:orientation="vertical"
Run Code Online (Sandbox Code Playgroud)
如果没有XML,我怎么能在代码中做到这一点?
如何为线性布局显示阴影.我想要白色圆形背景和线性布局周围的阴影.到目前为止我已经这样做了.请帮我.提前致谢.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@xml/rounded_rect_shape"
android:orientation="vertical"
android:padding="10dp">
<-- My buttons, textviews, Imageviews go here -->
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
和xml目录下的rounded_rect_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#ffffff" />
<corners
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp" />
</shape>
Run Code Online (Sandbox Code Playgroud) 我有一个TextView我想要在LinearLayout垂直排列元素使用的景观活动的底部固定.
我已经设置android:gravity="bottom"了文本视图,但它仍然喜欢在LinearLayout我不想要它的最后一个元素之下.
有什么建议?
有什么优势RelativeLayout超过LinearLayoutandroid系统?对于一个特定的设计,你更喜欢哪一个,背后的原因是什么?
它(RelativeLayout)是否与HTML相似或类似<div>?
android android-layout android-linearlayout android-relativelayout
如何在线性布局周围添加边框除了底部?LinearLayout需要在左侧,顶部和右侧具有边框,但不在底部.
我尝试将添加TextView到LinearLayout动态,如下面的代码,但是当我运行该应用程序也不会出现?
setContentView(R.layout.advanced);
m_vwJokeLayout=(LinearLayout) this.findViewById(R.id.m_vwJokeLayout);
m_vwJokeEditText=(EditText) this.findViewById(R.id.m_vwJokeEditText);
m_vwJokeButton=(Button) this.findViewById(R.id.m_vwJokeButton);
TextView tv=new TextView(this);
tv.setText("test");
this.m_vwJokeLayout.addView(tv);
Run Code Online (Sandbox Code Playgroud)
有什么问题?
我创建了一个替换为xml项的linearlayout.在这个线性布局中,我动态地放置了一些textview,因此不需要从xml中取出它们.现在我需要从linearlayout中删除这些textview.我试过这个:
if(((LinearLayout) linearLayout.getParent()).getChildCount() > 0)
((LinearLayout) linearLayout.getParent()).removeAllViews();
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我能怎么做?谢谢,马蒂亚
如何设置ViewGroup的最大宽度?我正在使用一个Theme.Dialog活动,然而,当调整大屏幕时,这看起来不那么好,它也有点轻量级,我不希望它占用整个屏幕.
我试过这个建议无济于事.此外,没有android:maxWidth像一些观点的属性.
有没有办法限制根LinearLayout,以便它只(例如)640 dip?我愿意为此换到另一个ViewGroup.
有什么建议?
我有一个带有较小TextView子项的自定义LinearLayout.我希望能够单击TextView未覆盖的区域,因此我将clickable = true和onclicklistener设置为LinearLayout,但不会触发onClick.如果我在TextView上设置onclick监听器,它按预期工作...
有人可以帮忙吗?
ar_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ar_item" android:layout_width="202dp"
android:layout_height="62dp" android:background="@drawable/bg_item_ar"
android:clickable="true">
<TextView android:id="@+id/ar_item_txt"
android:layout_width="164dp" android:layout_height="fill_parent"
android:paddingBottom="8dp" android:paddingLeft="8dp"
android:paddingTop="8dp" android:paddingRight="6dp" android:gravity="center"
android:background="#50000000" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的自定义LinearLayout
public class ARView extends LinearLayout
{
public ARView(final Context context, String name, String id)
{
super(context);
getLayoutInflater().inflate(R.layout.ar_item, this ,true);
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.ar_item, null);
TextView textView = (TextView) findViewById(R.id.ar_item_txt);
textView.setText(name);
setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Toast t = Toast.makeText(context, "hey!", Toast.LENGTH_SHORT);
t.show();
}
});
}
}
Run Code Online (Sandbox Code Playgroud) android ×10
onclick ×1
orientation ×1
radio-button ×1
radio-group ×1
textview ×1
view ×1
width ×1