我在layout.xml中有以下代码.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent">
<EditText android:hint="@string/feed_url"
android:id="@+id/feedUrl" android:textSize="14dp" android:inputType="textUri"
android:layout_marginRight="45dp" android:layout_height="wrap_content" android:layout_width="fill_parent">
</EditText>
<Button android:id="@+id/getGraph"
android:text="@string/get"
android:layout_toRightOf="@id/feedUrl"
android:layout_alignParentRight="true"
android:layout_height="wrap_content" android:width="45dp" android:layout_width="wrap_content">
</Button>
</RelativeLayout>
<WebView android:id="@+id/wv1" android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在eclipse插件布局创建器中,EditText和按钮正确显示.(见下面的截图)

但是在设备和模拟器上,按钮不会被隐藏.(见下面的截图)

知道为什么按钮隐藏在设备中?
我读过这篇文章:
到目前为止,如果我们在XML中设置权重和宽度,但是我想以编程方式进行操作.我的布局(XML)中有一个表,我正在以编程方式向其添加行.在每一行中,我添加了2个文本视图.我试过这样做:
TableLayout tl = (TableLayout)findViewById(R.id.myTable);
for(int i = 0; i < nl.getLength(); i++){
NamedNodeMap np = nl.item(i).getAttributes();
TableRow trDetails = new TableRow(this);
trDetails.setBackgroundColor(Color.BLACK);
TextView tvInfo = new TextView(this);
tvInfo.setTextColor(Color.WHITE);
tvInfo.setGravity(Gravity.LEFT);
tvInfo.setPadding(3, 3, 3, 3);
tvInfo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
tvInfo.setText("info");
TextView tvDetails = new TextView(this);
tvDetails.setTextColor(Color.WHITE);
tvDetails.setGravity(Gravity.LEFT);
tvDetails.setPadding(3, 3, 3, 3);
tvDetails.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
tvDetails.setText(np.getNamedItem("d").getNodeValue());
trDetails.addView(tvInfo, new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.50f));
trDetails.addView(tvDetails, new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.50f));
tl.addView(trDetails,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
Run Code Online (Sandbox Code Playgroud)
但没有运气,它显示空白屏幕,但如果我用XML做,那么它显示完美.请帮我解决这个问题,我做错了?
谢谢
A最近有一个自定义ListView.然后我必须显示没有滚动条的所有列表项.按照在LinearLayout中放置项目的方法,我改变了我的代码,但我无法将onClickListener绑定到新布局.在ListView中,我使用position var来确定触摸了哪个视图.但是在LinearLayout onClick中,回调没有位置参数.
这是我的BasketActivity.class:
package ru.**.**;
public class BasketActivity extends Activity {
ArrayList<Item> items = new ArrayList<Item>();
SQLiteDatabase database;
Map<String, ?> all;
ItemAdapter adapter;
Item item2delete;
View deletingView;
private SharedPreferences settings;
private SharedPreferences settings2;
private Basket basket;
TextView basketSum;
private int position2delete;
private Map<String, ?> all2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_basket);
<..cutted..>
settings = getSharedPreferences("basket", 0);
settings2 = getSharedPreferences("price", 0);
basket = new Basket(settings, settings2);
all = basket.getList();
LinearLayout l1 = (LinearLayout) findViewById(R.id.l1); …Run Code Online (Sandbox Code Playgroud) 我有一些LinearLayout包含一些东西的对象,包括两个TextViews。不幸的是,我在他们之间有一个巨大的空间,我不知道为什么。
自己看(在内容框架和#642954 - 14/25/9814事物之间):
http://i.stack.imgur.com/832QN.png
这是我的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="@string/smiley"
android:padding="10dp"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:includeFontPadding="false"
>
<TextView android:id="@+id/contenu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/round"
android:padding="10dp"
android:layout_margin="5dp"
android:includeFontPadding="false"
android:layout_marginBottom="-10dp"
/>
<TextView android:id="@+id/infos"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"
android:layout_margin="5dp"
android:includeFontPadding="false"
android:padding="0dp"
android:layout_marginTop="-10dp"
/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是round.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="#20000000" />
<corners android:radius="13dp" />
</shape>
</item>
<item android:bottom="2px">
<shape xmlns:android="http://schemas.android.com/apk/res/android" > …Run Code Online (Sandbox Code Playgroud) 我在父线性布局中有两个线性布局。所有水平。我想要全部l_child展示和部分r_child展示;而其余的r_child将在屏幕外右侧。我如何做到这一点?
<LinearLayout
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/l_child"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="@+id/r_child"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我想要一个可滚动的列表,其中还包括列表视图.我到处做研究,还没有解决方案:(根据下面的代码,当我添加ScrollView时,listview高度变得更小(单行).我希望ListView高度是动态的(基于内容)并且还可以完成页面可滚动.我如何实现这一目标?或者有没有办法创建动态线性/相对列表UI?请提示.
XML代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="@dimen/activity_horizontal_margin"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/kollege_name"
android:width="170dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="right"
android:text="@string/grade_value"
android:width="120dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView2"
android:layout_below="@+id/textView2"
android:text="@string/code_value" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@android:color/darker_gray" />
<TextView
android:id="@+id/textView4"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/your_fit"
android:textSize="12sp" />
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@android:color/darker_gray" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin" …Run Code Online (Sandbox Code Playgroud) android listview scrollview relativelayout android-linearlayout
我正在为android开发.该应用程序在线性布局中以XML格式设计.我想要做的是在连续的按钮/文本之间留下一些空白行,以确保GUI中的一些整洁.在线性布局中这样做是否可行?请帮忙...
我的问题非常短暂.我有一个基于LinearLayout的自定义控件.我从xml'膨胀它的视图,其中根被设置为元素.
现在,当我尝试通过"this.setPadding(x,x,x,x)"设置此自定义控件的填充时,它不会影响我稍后在几行代码中添加到此控件的TextView和ImageView.
目前我通过单独设置每个控件的边距来实现它,以实现整个自定义控件的全局填充,但是如果知道是否有使用setPadding dynamicaly,或者可能是我的错误,那将是很好的.
为了简化,我的案例看起来像这样:
setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
LinearLayout.LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT); setLayoutParams(LP);setPadding(0,30,0,30); //我知道它在px中
之后我添加了一个大图像,由于它的大小而缩小,但LinearLayout的填充(我尝试设置dynamicaly)不会影响它,只有我直接设置它的边距.
任何提示都会受到极大的关注.
我正在尝试实现如下布局:

两个视图,线性布局中的重量2(绿色视图)和1(蓝色视图).并且浮动按钮位于它们前面的那些视图之间.但是使用线性布局是不可能的.任何人都可以在这里给予一些帮助
更新:这就是我所做的
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#22B14C" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="To be a floating button" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#00A2E8" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
而我得到的是

我在LinearLayout中垂直排列了四个按钮。
我希望按钮之间的空间,最顶部按钮与线性布局的顶部之间的空间以及最底部按钮与布局的底部之间的空间相同。
在附图中,空格被描绘为红色路径。我希望所有空间都具有相同的大小。
我将如何实现自己的目标?
<LinearLayout
p1:orientation="vertical"
p1:layout_width="wrap_content"
p1:layout_height="wrap_content"
p1:id="@+id/mainButtonLayout">
<Button
p1:text="xxx"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/saButton"
p1:textColor="#FFFFFF"
p1:background="@drawable/roundedBlue"
p1:minHeight="33dp"
p1:minWidth="175dp"
p1:layout_marginBottom="20dp" />
<Button
p1:text="xxxx"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/rButton"
p1:textColor="#FFFFFF"
p1:background="@drawable/roundedBlue"
p1:minHeight="33dp"
p1:minWidth="175dp"
p1:layout_marginBottom="20dp" />
<Button
p1:text="xxxxx"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/sButton"
p1:textColor="#FFFFFF"
p1:background="@drawable/roundedBlue"
p1:minHeight="33dp"
p1:minWidth="175dp"
p1:layout_marginBottom="20dp" />
<Button
p1:text="xxxxx"
p1:layout_width="match_parent"
p1:layout_height="wrap_content"
p1:id="@+id/pButton"
p1:textColor="#FFFFFF"
p1:background="@drawable/roundedBlue"
p1:minHeight="33dp"
p1:minWidth="175dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)