标签: android-relativelayout

如何将RelativeLayout放在RelativeLayout的底部?

我有一个RelativeLayout,这个布局有两个孩子,一个是a MapView,另一个是RelativeLayout包含一个按钮.

我希望它看起来像那样

但我的透明框(a RelativeLayout)始终显示在地图的顶部.

<RelativeLayout 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">

  <com.google.android.maps.MapView
    android:id="@+id/mapView"/>

    <test.project.TransparentPanel 
      android:layout_width="fill_parent"
      android:layout_width="fill_parent">   

        <Button 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Click Me!"/>   

    </test.project.TransparentPanel>

</RelativeLayout>   
Run Code Online (Sandbox Code Playgroud)

(我在代码中遗漏了一些东西)

android android-linearlayout android-relativelayout

4
推荐指数
1
解决办法
3万
查看次数

相对布局wrap_content有什么作用?

我有一个简单的布局如下.即使我将所有属性设置为wrap_content,生成的布局也会明智地填充整个屏幕.各个布局本身很小.所以顶级容器应该只包含所有元素.但它似乎填满了整个屏幕.宽度方面,相同的属性工作正常.我在这里错过了什么?

<RelativeLayout 
    android:id="@+id/topcontainer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/solid_red"
>

<LinearLayout
    android:id="@+id/lowercontainer"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingBottom="10dip"
    android:layout_centerHorizontal="true"
    android:paddingLeft="0dip"
    android:paddingRight="0dip"
    android:layout_alignParentBottom="true"
    android:background="@drawable/solid_blue"
>

<ImageView
     android:id="@+id/lefticon"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" 
     android:background="@drawable/ic_settings_display"
     android:layout_alignParentLeft="true"
     android:layout_alignParentBottom="true"
     android:paddingRight="0dip"
/> 

<ImageView
     android:id="@+id/righticon"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" 
     android:background="@drawable/ic_settings_display"
     android:layout_alignParentRight="true"
     android:layout_alignParentBottom="true"
     android:paddingLeft="0dip"
/> 

</LinearLayout>

   <TextView android:id="@+id/test"
        android:text="Test text"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:paddingTop="10dip"
        android:gravity="center"
        android:layout_centerHorizontal="true"
        android:textSize="20dip"
        android:layout_above="@id/lowercontainer"
        android:background="@drawable/solid_green"
   />         

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

替代文字

android android-relativelayout

4
推荐指数
1
解决办法
3981
查看次数

LinearLayout将孩子放在右侧

我试图在水平方向的线性布局中使用textview和按钮.textview应出现在开头,按钮应出现在结尾处.我认为将重力直接按到按钮就可以了,但按钮不会移动到右侧.我在想我是否应该使用相对布局?

在此输入图像描述

<\LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:orientation="horizontal">

    <TextView
        android:id="@+id/productPriceTextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Rs 3579.0" 
        />

    <Button
        android:id="@+id/buyNowButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="Buy Now" />
<\/LinearLayout>
Run Code Online (Sandbox Code Playgroud)

layout android android-linearlayout layout-gravity android-relativelayout

4
推荐指数
3
解决办法
2万
查看次数

Android - OnTouchListener无法正常工作

您好我已经构建了一个具有root relativelayout视图的应用程序.当用户触摸屏幕时,我试图设置一个触摸式监听器返回,但它似乎没有触发,我无法弄清楚我哪里出错了.我搜索过并在线查看,但从我看到的每个人似乎都使用与我相同的方法 - 我只是不起作用.
谁能明白为什么?

  RelativeLayout relativeLayout;

  relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);

 //relative layout on touch listener
    relativeLayout.setOnTouchListener(new View.OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent event) {

            //down - finger on screen
            if (event.getAction()== MotionEvent.ACTION_DOWN) {

                //store center of screen lat lon
                centerOfScreenLatLng = getScreenCenterLatLon();

                toastMsg = "down";
                toastShort();

                return true;
            }

            //up - finger off screen
            else if (event.getAction() == MotionEvent.ACTION_UP) {

                toastMsg = "up";
                toastShort();

                //get center of screen lat lon
                LatLng centerPoint = getScreenCenterLatLon();

                //if not equal then …
Run Code Online (Sandbox Code Playgroud)

android ontouchlistener touch-event android-view android-relativelayout

4
推荐指数
1
解决办法
2880
查看次数

layoutLelout的layout_below和weightsum以编程方式

LinearLayout是以RelativeLayout编程方式创建的.我想要做的是分配weigtsumin LinearLayout并想要设置layout_above属性.问题是weightSum可用的,LinearLayout.LayoutParams并且layout_above可用RelativeLayout.LayoutParams.目前,我在做

LinearLayout ll_menu_code = new LinearLayout(this);
        ll_menu_code.setId(1001);
        LinearLayout.LayoutParams parmas_ll_menu_code = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 2f);
        parmas_ll_menu_code.setMargins(0, 20, 0, 0);
        ll_menu_code.setLayoutParams(parmas_ll_menu_code);
Run Code Online (Sandbox Code Playgroud)

哪个设置了weightSum.怎么设置layout_above?应该如何设置这两个属性?

我想以xml编程方式创建以下布局

<LinearLayout
                                android:layout_below="@id/ll_menu_code"
                                android:id="@+id/ll_quantity"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_marginTop="20dp"
                                android:weightSum="5">
Run Code Online (Sandbox Code Playgroud)

android android-layout android-linearlayout android-relativelayout

4
推荐指数
1
解决办法
2306
查看次数

如何以编程方式添加水平分隔线

在 bleow 发布的代码中,我试图在每个添加到线性布局的视图之后添加一个水平分隔符,如代码所示。我的问题是,在运行时分频器没有显示

请让我知道为什么分隔符没有显示以及如何让它出现?

代码

private void inflateView(String bez, String ges) {
    LinearLayout linLay = (LinearLayout) findViewById(R.id.versicherungsListeActivity2mod_linLay_meineDocList_container);

    //divider
    View viewDivider = new View(this);
    viewDivider.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    viewDivider.setBackgroundColor(Color.parseColor("#000000"));

    LayoutInflater inflator = this.getLayoutInflater();
    View view = inflator.inflate(R.layout.versicherung_docs_row_model, null);//<<<<<< this is the view i want to add to the map as a key

    ImageView imgViewLogo = (ImageView) view.findViewById(R.id.versicherungslisteactivity2_docs_lisvie_row_model_imgVie_logo);
    TextView texVieBez = (TextView) view.findViewById(R.id.versicherungslisteactivity2_docs_lisvie_row_model_texVie_docBezeichnung);
    TextView texVieExtraItem = (TextView) view.findViewById(R.id.versicherungslisteactivity2_docs_lisvie_row_model_texVie_addMoreDocs);
    TextView texVieGes = (TextView) view.findViewById(R.id.versicherungslisteactivity2_docs_lisvie_row_model_texVie_docGesellschaft);
    Button btnMore = (Button) view.findViewById(R.id.versicherungslisteactivity2_docs_lisvie_row_model_btn_more);


    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) …
Run Code Online (Sandbox Code Playgroud)

android view android-linearlayout android-relativelayout

4
推荐指数
1
解决办法
4654
查看次数

相对布局对齐右下角的图像

我使用相对布局将一个较小的图像叠加在较大的图像上.我希望较小图像的右下角与较大图像的BR角一致.我在我的布局xml中使用了边距参数(指定在倾角中测量),但这似乎并不适用于所有设备和分辨率 - 在某些情况下,小图像从边框移动了4-5px.

是否可以指定较小图像的位置而没有像素值?即重力还是什么?

android android-layout android-relativelayout

3
推荐指数
1
解决办法
7606
查看次数

Android相对布局:ToLeftOf去了视图

我有一个相对布局,其中我有一个TextView在左边和一个微调器在右边.另外,我需要一个错误图像来显示用户是否选择了错误的变体.

 <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:gravity="center_vertical"
            android:text="@string/some_text"/>
        <Spinner
            android:id="@+id/spinner"
            android:layout_width="74dp"
            android:layout_height="40dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/err"/>
        <ImageView

            android:id="@+id/err"
            android:layout_centerVertical="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:src="@drawable/ic_error"/>
    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

当错误未显示(visibility = GONE)时,我希望我的微调器在右侧对齐,并在错误可见时将其移动到错误图像的左侧.我怎么做?现在它只是忽略了这个:

android:layout_toLeftOf="@+id/err"
Run Code Online (Sandbox Code Playgroud)

编辑:谢谢,我纠正了错字,但这不是问题的原因

android android-relativelayout

3
推荐指数
1
解决办法
2957
查看次数

FindViewById在自定义相对布局上返回null

在init方法中,findViewById在R.id.disable_view_content上返回null。

public class DisableView extends RelativeLayout {

    private View content;
    private View disableView;
    private int disableBackgroundColor;
    private boolean isEnabled;

    public DisableView(Context context) {
        super(context);
        init();
    }

    public DisableView(Context context, AttributeSet attrs) {
        super(context, attrs);
        obtainAttributes(context, attrs);
        init();
    }

    public DisableView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        obtainAttributes(context, attrs);
        init();
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public DisableView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        obtainAttributes(context, attrs);
        init();
    }

    private void obtainAttributes(Context context, AttributeSet attributeSet) {
        TypedArray …
Run Code Online (Sandbox Code Playgroud)

android android-custom-view android-relativelayout

3
推荐指数
1
解决办法
697
查看次数

如何在android中的布局上实现左/右滑动/拖动

我正在开发一个Android应用程序,在该应用程序中,相对布局上有滑动功能,用户可以向左和向右滑动.请指教.

android swipe android-relativelayout

3
推荐指数
1
解决办法
4713
查看次数