标签: layoutparams

在LinearLayout中更改LayoutParams的动画

在我的应用程序中有一个LinearLayout,其布局高度为0.当我单击按钮时,此布局高度应为LayoutParams.WRAP_CONTENT.这是我在onclicklistner中使用的代码.

LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
slider.setLayoutParams(lp);
Run Code Online (Sandbox Code Playgroud)

我想动画这个.如何将动画设置为滑块.

android android-animation android-layout layoutparams

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

android从全屏模式退出

我在Android工作.我需要以全屏模式显示我的活动,我使用以下代码完成此操作.

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)

现在它看起来像这样: - 在此输入图像描述

现在我想退出这个完整模式,所以我的活动应该像以前一样显示.像这样:-

在此输入图像描述

我有一个按钮,用于在完全模式或正常模式之间切换,我将一次又一次地切换模式.请建议我怎么做这个.意味着如何从全屏获得正常的屏幕.

先感谢您.

android layoutparams android-windowmanager

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

使用编程方式Android添加参数布局

你好我有一个主屏幕.

<RelativeLayout 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"
tools:context=".MainActivity" >
<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"/>
<ImageButton
    android:id="@+id/imageButton1"
    android:layout_width="55dp"
    android:layout_height="50dp"
    android:layout_alignParentTop="true"
    android:layout_marginTop="10dp"
    android:layout_toLeftOf="@+id/toggleButton1"
    android:background="@android:drawable/btn_default"
    android:contentDescription="@string/app_name"
    android:scaleType="centerCrop"
    android:src="@drawable/plus_grey" />

<LinearLayout
    android:id="@+id/lay"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_marginEnd="0dp"
    android:background="#A0FFFFFF"
    android:orientation="horizontal"
    android:visibility="invisible" >

    <TextView
        android:id="@+id/locinfo"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:textColor="@color/cherniy"
        android:textSize="20sp"
        android:visibility="visible" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

并且有一个imageButton

                    button = (ImageButton) findViewById(R.id.imageButton1);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v)  {
                if (bIcon == false) {
                    button.setImageResource(R.drawable.plus_yellow);                                                                   
                    m = myMap.addMarker(new MarkerOptions().position(myMap.getCameraPosition().target).draggable(true));                     
                    LinearLayout linLayout = (LinearLayout)findViewById(R.id.lay);
                    t = (TextView)findViewById(R.id.locinfo);                      
                    linLayout.setVisibility(View.VISIBLE);
                    t.setVisibility(View.VISIBLE);                      
                                bIcon …
Run Code Online (Sandbox Code Playgroud)

android android-layout layoutparams android-activity

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

Android视图的getTop(),getLeft(),getX(),getY(),getWidth(),getHeight()方法

我正在编写一个拖放应用程序,因为一些参数而感到非常困惑.

请帮忙搞清楚.

首先,我阅读了该View课程的文档并得到了以下解释.

getX() : The visual x position of this view, in pixels.

getY() : The visual y position of this view, in pixels.

getWidth() : Return the width of the your view.

getHeight() : Return the width of the your view.

getTop() : Top position of this view relative to its parent.

getLeft() : Left position of this view relative to its parent.

现在,当我们完成官方文档时,让我们看看我们有什么.

我有一个原始大小的图像500x500叫做圆圈.

在此输入图像描述

这是我的应用程序的实际屏幕截图

在此输入图像描述

这是布局的xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center">

    <ImageView
        android:id="@+id/imageView1" …
Run Code Online (Sandbox Code Playgroud)

android view layoutparams

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

Android:更改WindowManager添加的ViewParams of View

我有叠加View管理WindowManager,就像在这个问题中一样.

简而言之,它看起来像这样:

WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
my_view_layout_params = new WindowManager.LayoutParams(
       WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
       WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
       PixelFormat.TRANSLUCENT);

wm.addView(my_view, my_view_layout_params);
Run Code Online (Sandbox Code Playgroud)

它工作,但如果我需要更改布局参数,我需要删除视图并再次添加它,如下所示:

wm.removeView(my_view);
wm.addView(my_view, my_view_layout_params);
Run Code Online (Sandbox Code Playgroud)

它看起来不是很漂亮.我试着这样做my_view.setLayoutParams(my_view_layout_params),但不幸的是它不起作用.我该怎么做?

android view layoutparams

12
推荐指数
2
解决办法
7768
查看次数

ICS中的TYPE_SYSTEM_OVERLAY

在Honeycomb中,我能够使用TYPE_SYSTEM_OVERLAY创建系统覆盖,并使用FLAG_WATCH_OUTSIDE_TOUCH接收触摸.

现在ICS改变了一些东西.我仍然可以创建系统覆盖,但我无法接触.

现在,我能够使用TYPE_SYSTEM_ALERT创建相同的内容并获取触摸,但它只是捕获touchevents,而不是像Honeycomb那样传递它们.

有任何想法吗?

亲切的问候

android layoutparams android-windowmanager android-4.0-ice-cream-sandwich

12
推荐指数
2
解决办法
1万
查看次数

如何在android中获取显示图像的宽度和高度?

这个问题可能看似微不足道,并且多次被问过,但我找不到对我有用的答案.

我有一个ImageViewGLSurfaceView被绘制在上面ImageView,当我按下一个按钮.

对于我,ImageView我传递一个Bitmap并缩小它以避免OutOfMemoryError异常.我ImageView与UI中的其他元素对齐,因此它会拉伸图像以填充宽度/高度(这就是我想要的).

当我从改变ImageViewGLSurfaceView我避开我的形象曾经是我的透明的黑色区域ImageView,因为GLSurfaceView使得UI有一个洞,工作方式不同比平时元素它吸引我的形象,以黑色的背景,我并不需要它,因为我有自定义背景.

我来到了一个解决方案来LayoutParams进行GLSurfaceView编程和我使用的Bitmap宽度和高度,但我结束了一个更小的图像.我需要显示图像的确切宽度和高度 - 而不是ImageView因为它有透明区域.

PS:我不是OpenGL专家,如果你有一个适用于OpenGL的解决方案,请分享.

一个)

 _______________
|               |
|               |
|---------------|          <-
|   transparent |     
|---------------| <-            Entire
|               |               ImageView
|     Image     |   need
|               | only this
|---------------| <-
|   transparent |
|---------------|          <-
|               |
 ---------------
Run Code Online (Sandbox Code Playgroud)

b)

 _______________
|               |
|               |
|---------------| …
Run Code Online (Sandbox Code Playgroud)

android width glsurfaceview imageview layoutparams

12
推荐指数
1
解决办法
883
查看次数

以编程方式将余量设置为CardView

我有一个CardViewXML布局,我需要以编程方式设置边距(这是因为我不需要任何时间的边距.基于几个条件,我设置或删除边距).

我是这样做的:

CardView.LayoutParams layoutParams = (CardView.LayoutParams) myCardView.getLayoutParams();
layoutParams.setMargins(0, 0, SystemHelper.dpToPx(2), 0);
myCardView.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)

这很好.它把2dp保证金放在我的底部CardView.但是,我在logcat中得到了这个:

java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams
Run Code Online (Sandbox Code Playgroud)

所以我改成CardView.LayoutParamsFrameLayout.LayoutParams,像这样:

FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) myCardView.getLayoutParams();
layoutParams.setMargins(0, 0, SystemHelper.dpToPx(2), 0);
myCardView.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)

然而,它仍然有效,但我得到与上面相同的错误.

所以我再修改一次使用它LinearLayout.LayoutParams.

LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) myCardView.getLayoutParams();
layoutParams.setMargins(0, 0, SystemHelper.dpToPx(2), 0);
myCardView.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)

当我这样做时,我没有得到错误,但它没有设置任何余量.

我应该忽略错误吗?这似乎不对.

编辑:

这是我CardView的XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="horizontal"
    android:background="@android:color/white"
    android:minHeight="@dimen/item_min_height"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        android:id="@+id/cardViewAppointmentWeek"
        app:cardElevation="2dp"
        android:layout_marginBottom="2dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"> …
Run Code Online (Sandbox Code Playgroud)

android android-layout layoutparams android-cardview android-layoutparams

12
推荐指数
2
解决办法
9028
查看次数

java.lang.ClassCastException:android.view.ViewGroup $ LayoutParams无法强制转换为android.widget.RelativeLayout $ LayoutParams

您好我刚刚编辑了我的XML,我把幻灯片菜单代码放在我的XML中,但这是错误的.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    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="#ffffff" >

    <ListView 
        android:id="@+id/menu_content_menulist"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="8dp"

        android:cacheColorHint="@android:color/transparent" 
        android:divider="@null"
        android:listSelector="@null"/>      
    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <com.mozaik.tangsel.side_menu_scroll.ScrollerLinearLayout       
            android:id="@+id/menu_content_side_slide_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"        
            android:orientation="verti_

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/content_statis"        
        android:orientation="vertical"
        android:background="@drawable/bg_app"
         >

        <include layout="@layout/layout_action_bar" />
    <ScrollView
        android:id="@+id/SV"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" 
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="4dp"
                android:background="@drawable/inbox_interface"
                android:orientation="vertical" >

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

                    <ImageView
                        android:id="@+id/ImageMozaikTangsel"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="10dip" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tabMozaikTangselLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >
                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

</ScrollView>

   </LinearLayout>
</com.mozaik.tangsel.side_menu_scroll.ScrollerLinearLayout>
</RelativeLayout> …
Run Code Online (Sandbox Code Playgroud)

java android android-layout layoutparams android-relativelayout

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

以编程方式在RecyclerView上设置保证金

我需要以编程方式在RecyclerView上设置上边距,但我得到以下异常:

java.lang.RuntimeException: Unable to resume activity java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams

这是我的代码:

RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams)recyclerView.getLayoutParams();
int marginTopDp = (int)getResources().getDimension(R.dimen.margin);
int marginTopPx = (int) (marginTopDp * getResources().getDisplayMetrics().density + 0.5f);
layoutParams.setMargins(0, marginTopPx, 0, 0);
recyclerView.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)

如果我使用ViewGroup.LayoutParams layoutParams = recyclerView.getLayoutParams堆栈跟踪建议,我不能再调用setMargin因为该方法不存在ViewGroup.LayoutParams.

任何帮助,将不胜感激.

android layoutparams android-recyclerview

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