如何以编程方式在"regler"和"decommender"按钮之间设置20dp的余量.

这是我的工作
LinearLayout lytmain = new LinearLayout(Mcontex);
lytmain.setOrientation(LinearLayout.VERTICAL);
LinearLayout lytdate = new LinearLayout(Mcontex);
LinearLayout lytbutton = new LinearLayout(Mcontex);
lytbutton.setBackgroundResource(R.color.black);
lytbutton.setBackgroundResource(R.color.black);
lytdate.setBackgroundResource(R.color.black);
lytmain.setBackgroundResource(R.color.black);
Button btnset = new Button(Mcontex);
Button btncancel = new Button(Mcontex);
btncancel.setShadowLayer(2, 1, 1, R.color.black);
btnset.setShadowLayer(2, 1, 1, R.color.black);
btnset.setBackgroundResource(R.drawable.black_button);
btncancel.setBackgroundResource(R.drawable.black_button);
btnset.setTextColor(Mcontex.getResources().getColor(R.color.white));
btncancel.setTextColor(Mcontex.getResources().getColor(R.color.white));
btncancel.setTextSize(15);
btnset.setTextSize(15);
btnset.setText("Régler");
btncancel.setText("Décommander");
btnset.setGravity(Gravity.CENTER);
btncancel.setGravity(Gravity.CENTER);
final WheelView month = new WheelView(Mcontex);
final WheelView year = new WheelView(Mcontex);
final WheelView day = new WheelView(Mcontex);
lytdate.addView(day, new LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1.2f));
lytdate.addView(month, new LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 0.8f)); …Run Code Online (Sandbox Code Playgroud) 我的申请有问题.我最近添加了ScrollView作为LinearLayout的Parent.将设备方向翻转为横向时,我的按钮会在顶部被切断.当我向下滚动时,我可以看到最后一个按钮就好了,在它的末尾有额外的"黑色空间",只有顶部被切掉了.我环顾四周,我不确定为什么会这样.这是一些图片,所以你可以理解它的外观.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center_vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<Button
android:id="@+id/BeefButton"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/beefbutton"
android:text="Beef"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"/>
<Button
android:id="@+id/PoultryButton"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="match_parent"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/chickenbutton"
android:text="Poultry"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"/>
<Button
android:id="@+id/FishButton"
android:layout_height="wrap_content"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/fishbutton"
android:text="Fish"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"
android:layout_gravity="center"
android:layout_width="match_parent"/>
<Button
android:id="@+id/PorkButton"
android:layout_height="wrap_content"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/porkbutton"
android:text="Pork"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"
android:layout_gravity="center"
android:layout_width="match_parent"/>
<Button
android:id="@+id/VegetablesButton"
android:layout_height="wrap_content"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/vegetablesbutton"
android:text="Vegetables"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"
android:layout_gravity="center"
android:layout_width="match_parent"/>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud) 任何人都可以帮我如何为linearlayout启用滚动功能?
我有一个LinearLayout设置高度为match_parent,如下所示:
<LinearLayout
android:id="@+id/list_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
Run Code Online (Sandbox Code Playgroud)
我想得到这个LinearLayout的高度.
我使用下面的代码:
LinearLayout ll_list = (LinearLayout)findViewById(R.id.list_layout);
int h = ll_list.getHeight();
Run Code Online (Sandbox Code Playgroud)
但它返回null.
我能怎么做?
我必须将单线性布局拆分为两列(如报纸列).线性布局包含文本视图和图像视图
我已经占据了屏幕宽度,并将其分成了一半,TextView然后ImageView进入第一列,即下图中的A B C 块.现在剩下的TextView并且' ImageView必须转到下一列,D E F就像它继续下去一样那么如果有人给我任何代码或想法来实现这个将是有帮助的..我尝试过GridView哪个不适合我的问题.由于TextView和ImageView尺寸不明确.

我不知道如何拆分Liner布局.我尝试像这样计算rootlayout高度
linearLayout.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
int linsize=linearLayout.getHeight();
int relsize=root.getHeight();
int textsize=txt1.getHeight();
mainheight=relsize;
subheight=linsize;
Toast.makeText(getApplicationContext(), "Linerlayout "+linsize, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Relative layout"+relsize, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "text height "+textsize, Toast.LENGTH_LONG).show();
if(mainheight==subheight)
{
Toast.makeText(getApplicationContext(), "make a new linear layout", Toast.LENGTH_LONG).show();
createsubview();
}
}
});
Run Code Online (Sandbox Code Playgroud)
截图

这是我正在研究的xml布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<ScrollView
android:layout_weight="2"
android:id="@+id/scrollConfirm"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ScrollView>
<LinearLayout
android:layout_marginTop="20px"
android:layout_weight="1"
android:id="@+id/imageNumpad"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="@drawable/myicon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#FFFFFF"
/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
由于我已经设置了ScrollView layout_weight="2"和LinearLayout(子),layout_weight="1"我预计ScrollView会占用LinearLayout两倍的可用空间.但我得到了相反的结果.ScrollView小于LinearLayout.而如果我为ScrollView layout_weight="1"和LinearLayout设置layout_weight="2",则ScrollView大于LinearLayou.
这怎么可能??
我正在尝试为containerLinearLayout(20dp)和btn按钮(20dp)设置动画(向右移动它们),但它们会在mainLinearLayout(40dp)的整个宽度之后被剪切.我试过clipChildren="false"这两个,但它不起作用.我不能使用match_parent尺寸布局,因为它是一个叠加应用程序,将阻止后面的触摸.
有任何想法吗?
我的布局:
<LinearLayout
android:id="@+id/main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false" >
<LinearLayout
android:id="@+id/container"
android:layout_width="20dp"
android:layout_height="80dp"
android:clipChildren="false"
android:clipToPadding="false" >
</LinearLayout>
<ImageButton
android:id="@+id/btn"
android:layout_width="20dp"
android:layout_height="80dp"
android:padding="0dp"
android:background="@drawable/btn" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的(简化)代码:
super.onCreate();
windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
params = new WindowManager.LayoutParams(
LayoutParams.WRAP_CONTENT, //can't have MATCH_PARENT
LayoutParams.WRAP_CONTENT, //can't have MATCH_PARENT
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT |
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
main = (LinearLayout) inflater.inflate(R.layout.main,null);
btn = (ImageButton)main.findViewById(R.id.btn);
container = (LinearLayout)main.findViewById(R.id.container);
btn.setOnClickListener(onClickListener);
windowManager.addView(main, params);
}
Run Code Online (Sandbox Code Playgroud)
动画代码: …
我有一个简单的布局,顶部有一个名字,还有一个我希望位于屏幕底部的按钮,或者我想要添加更多项目的按钮.
所以我使用带有LinearLayout的ScrollView,如下所示:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:fillViewport="true"
android:focusableInTouchMode="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
tools:context=".ItemDetailActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- Name -->
<RelativeLayout
android:id="@+id/top_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top" >
<TextView
android:id="@+id/name_label"
style="@style/Header_Label_TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/name" />
<TextView
android:id="@+id/name_value"
style="@style/Value_Label_TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/name_label" />
</RelativeLayout>
<!-- button -->
<RelativeLayout
android:id="@+id/ButtonLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
<Button
android:id="@+id/add_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:onClick="editItem"
android:text="@string/button_edit" />
</RelativeLayout>
<requestFocus />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:

如何使按钮出现在屏幕底部或更远处.在线搜索,大多数答案是设置`android:fillViewport ="true",但这没有帮助.我究竟做错了什么?
android android-layout android-linearlayout android-scrollview android-relativelayout
我需要相对/线性布局的运行时尺寸.
activity_home.xml:
<RelativeLayout
android:id="@+id/rlParent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
HomeActivity.java:
private int width, height;
RelativeLayout rlParent = (RelativeLayout) findViewById(R.id.rlParent);
w = rlParent.getWidth();
h = rlParent.getHeight();
Log.i("Width-Height", width+"-"+height);
Run Code Online (Sandbox Code Playgroud)
请分享你的想法.
我动态地将图像视图添加到我的线性布局中,
我想实现
以下是我所做的示例代码
主要活动
package ksp.com.animationssample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
private Button btn_expand;
private Button btn_collapse;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_expand = (Button) findViewById(R.id.btn_expand);
btn_collapse = (Button) findViewById(R.id.btn_collapse);
LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
final LinearLayout layout = (LinearLayout) findViewById(R.id.imageLayout);
for (int i = 0; i < 3; i++) {
final ImageView image = new ImageView(MainActivity.this); …Run Code Online (Sandbox Code Playgroud)