小编0X0*_*gar的帖子

带有多个倒计时器的Recyclerview会导致闪烁

我想表明我的每个单元格内剩下多少时间RecyclerView......因为我已经为每个单元格使用了倒数计时器.在每一行我开始一个计数器并管理onTick()...所有工作都按预期工作...我有一个计时器勾选每一行,我的单元格也在更新但我的单元格现在闪烁....当它变得疯狂时我滚动.

这是我的适配器......

if (product.getProductType().equalsIgnoreCase("Auction Product")) {
                isAuction=true;
                viewHolder.img_product_type.setImageResource(R.drawable.bid);
                viewHolder.txt_timeleft.setVisibility(View.VISIBLE);
               start_countDown(product.getStart(),product.getStop(),viewHolder.txt_timeleft);
            }
Run Code Online (Sandbox Code Playgroud)

计数器代码如下....

private void start_countDown(String start, String stop, final TextView txt_timeleft) {
        try {
            //Log.e("hetal",start+"....."+stop);
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            Calendar start_date = Calendar.getInstance();
            start_date.setTime(format.parse(start));

            Calendar end_date = Calendar.getInstance();
            end_date.setTime(format.parse(stop));

            final Calendar today = Calendar.getInstance();
            CountDownTimer timer;

            txt_timeleft.setTextColor(Color.DKGRAY);
            if(today.before(start_date)){
                txt_timeleft.setTextColor(context.getResources().getColor(R.color.red));
                txt_timeleft.setText(context.getString(R.string.auction_not_start));
                Animation anim = new AlphaAnimation(0.0f, 1.0f);
                anim.setDuration(1000); //You can manage the time of the blink with this parameter
                anim.setStartOffset(20);
                anim.setRepeatMode(Animation.REVERSE);
                anim.setRepeatCount(Animation.INFINITE);
                txt_timeleft.startAnimation(anim);
                return;
            } …
Run Code Online (Sandbox Code Playgroud)

android countdowntimer android-recyclerview

8
推荐指数
1
解决办法
7083
查看次数

材料设计 - 操作栏标题和内容的左边距不匹配

我正在尝试按照布局指南- 指标和线条设置屏幕边距.具体而言,移动屏幕上的列表内容应具有72 dp的边距,并与指南中所示的标题一致:

在此输入图像描述

由于Android Studio会自动在res/dimens.xml中生成边距值,我认为我会通过添加自己的"内部"边距来使我的内容与标题保持一致:

dimens.xml

<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>

    <!-- 16 + 56 = 72 = "Content left margin from screen edge" -->
    <dimen name="content_horizontal_margin">56dp</dimen>
</resources>
Run Code Online (Sandbox Code Playgroud)

myactivity.xml

<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin">

    <TextView
        android:id="@+id/tvEditPlaylistInfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="@dimen/content_horizontal_margin"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="test" />

    <ImageButton
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:src="@drawable/action_current"
        android:layout_alignBottom="@id/tvEditPlaylistInfo"
        android:layout_toRightOf="@id/tvEditPlaylistInfo"
        android:layout_marginLeft="16dp"/>

    <ListView
        android:id="@+id/lvAudioFiles"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/content_horizontal_margin"
        android:layout_below="@id/tvEditPlaylistInfo">
    </ListView>

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

但不知何故,我的内容被"关闭"大约8dp(模拟器,Lollipop 22).

在此输入图像描述

我正在使用父母的自定义主题,Theme.AppCompat.Light.DarkActionBar但我只改变颜色,所以我认为这不是我的问题的根源. …

android android-layout material-design

7
推荐指数
1
解决办法
2519
查看次数

JavaFX 中 tableview 单元格中的组合框

我正在尝试添加一个Combo Box到我的Table View

基本上我有一个名为 TableViewTest 的类,它存储一个名称和一个描述,我可以Table View毫不费力地显示这些名称和描述,但我想要做的是添加第三列,每个单元格都有一个,Combo Box以便用户可以选择一个从每个人的多个选项。

到目前为止,我已经创建了一个具有一些值ObservableList的类型String并将它们添加到一个ComboBox对象中。有谁知道我可以将它添加Combo Box到表格中的方法吗?

还要记住,这段代码非常粗糙,我只是想让一些东西工作,我将在以后重构代码。

ObservableList<TableViewTest> products = FXCollections.observableArrayList();

    for(int i = 0; i < b.length; i++){

        // random String values
        products.add(new TableViewTest(b[i], a[i]));
    }

ObservableList<String> options = FXCollections.observableArrayList(
                                "1",
                                "2",
                                "3"
                                );
final ComboBox comboBox = new ComboBox(options);

TableColumn<TableViewTest, String> nameColumn = new TableColumn<> ("Name");
nameColumn.setMinWidth(200);
nameColumn.setCellValueFactory(new PropertyValueFactory<TableViewTest, String>("name"));

                //price Column
                //Stock Column
TableColumn<TableViewTest, String> StockColumn = …
Run Code Online (Sandbox Code Playgroud)

java combobox javafx

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

如何以编程方式添加GridLayout子项的layout_columnWeight?

我想使用GridLayout(不GridView)作为象棋或棋子等游戏的棋盘.由于我有点不愿意使用带有64个孩子View的xml文件,我尝试以编程方式添加它们.

为了简单起见,我开始使用TextViews作为孩子ViewGridLayout.

我的问题是Views不是均匀分布的,而且我不知道如何在我的java代码中获得均匀分布.设置layout_columnWeight和没有类似"setWeight()"的方法layout_rowWeight.

目前,这是我的activity_dynamic_grid_layout.xml:

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

<ImageView
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:id="@+id/ivLogo"
    android:background="#ff0000"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"/>

<android.support.v7.widget.GridLayout
    android:id="@+id/grid_layout"
    android:background="#004080"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/ivLogo"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="36dp">

</android.support.v7.widget.GridLayout>
Run Code Online (Sandbox Code Playgroud)

我已经将GridLayout宽度和高度设置为match_parent这里,但我在运行时使用a ViewTreeObserver.OnPreDrawListener来更改它们以获得方块板.这是有效的,彩色背景显示了预期的方形空间.

我的onCreate()

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dynamic_grid_layout);

    GridLayout gl = (GridLayout) findViewById(R.id.grid_layout);
    gl.setColumnCount(8);
    gl.setRowCount(8);

    for(int i=0; i<gl.getRowCount(); i++)
    {
        GridLayout.Spec rowSpec = GridLayout.spec(i, 1, …
Run Code Online (Sandbox Code Playgroud)

java android android-gridlayout

7
推荐指数
2
解决办法
4141
查看次数

ConstraintLayout Flow帮助程序示例

我在一个博客条目中读到,在ConstraintLayout2.0.0中引入了一种创建视图流的方法。我真正想要实现的是:我有几个TextView彼此固定大小的。根据屏幕大小,一些TextView应当推入下一行。

大屏幕上有六个示例TextViews

[AAA] [BBB] [CCC] [DDD]

[EEE] [FFF]

在具有六个小屏幕的示例TextViews

[AAA] [BBB]

[CCC] [DDD]

[EEE] [FFF]

我已经看到了这个#1问题的提出使用FlexboxLayout,但有一个评论说,同样的事情现在可以使用来实现ConstraintLayout

任何人都可以给我一个例子,说明如何使用来实现所需的行为ConstraintLayout?我找不到关于此的任何说明。提前致谢。

xml layout android android-constraintlayout

7
推荐指数
1
解决办法
1436
查看次数

如何在Android中创建AttributeSet?

我试图在Android中编写一些代码来设置AttributeSetfrom attrs.xml文件中的参数.但我收到"资源未找到"错误.

Java代码

MainActivity.java

package com.example.mycompoundbutton;

import org.xmlpull.v1.XmlPullParser;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Xml;
import android.app.Activity;
import android.content.res.Resources;


public class MainActivity extends Activity 
{

@Override
protected void onCreate(Bundle savedInstanceState) 
{

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    Resources res = this.getResources();

    XmlPullParser parser = res.getXml(R.attr.xyz);

    AttributeSet attrs = Xml.asAttributeSet(parser);

    MyCompound my = new MyCompound(this,attrs);

    my.MyTestFun(300,500);

}
}
Run Code Online (Sandbox Code Playgroud)

MyCompound.java

package com.example.mycompoundbutton;


import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.CompoundButton;

public class MyCompound extends CompoundButton
{

public MyCompound(Context context, AttributeSet attrs) 
{

        super(context, attrs);

        TypedArray …
Run Code Online (Sandbox Code Playgroud)

xml android xmlpullparser android-attributes

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

如何停止Glide upscaling?

我正在使用Glide图像加载库,我在调整位图大小时遇到​​了问题.

使用以下代码时:

Glide.with(getActivity())
    .load(images.get(i))
    .asBitmap().centerCrop()
    .into(new SimpleTarget<Bitmap>(1200, 1200) {
        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {

        }
    });
Run Code Online (Sandbox Code Playgroud)

每个位图都会调整大小到指定的尺寸.因此,如果图像是400x300,它会升级到1200 x 1200,这是我不想要的.如何使图像小于指定的尺寸,它不会调整大小?

我正在指定尺寸,因为我希望每个大于指定尺寸的图像都要考虑到尺寸centerCrop; 然后如果图像小于指定的尺寸,我不希望它的大小调整.

android android-glide

6
推荐指数
1
解决办法
806
查看次数

Cookie不会存储在Android Webview API 21及更高版本中

背景:

Webview在API 21中遇到了一个非常令人困惑的行为,在真实设备中进行测试时.

我有一个本地HTML5应用程序(内部资产文件夹)具有以下功能

  • 登录(2步验证).
  • 根据身份验证显示项目列表.

问题:

执行登录请求后,服务器返回会话cookie.Webview使用API​​ 21或更高版本的真实设备时,此cookie不会存储.如果我使用模拟器(在本例中为Genymotion),则会正确存储cookie.

更多信息:

执行身份验证的请求具有以下标头:

POST http://myServer/j_spring_security_check HTTP/1.1
Proxy-Connection: keep-alive
Content-Length: 101
access-control-allow-origin: *
accept: application/json
access-control-allow-credentials: true
User-Agent: Framework/1.5.0 (Linux; U; Android 6.0.1; Nexus 5X Build/MMB29Q) App/0.1.1
Origin: file://
content-type: application/x-www-form-urlencoded
Accept-Language: en-US
X-Requested-With: app.package
Host: myServer
Run Code Online (Sandbox Code Playgroud)

通过以下回复:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=4D169E8656DBEDFFA4D17FE8D436A5BA; Expires=Fri, 19-Feb-2016 14:27:55 GMT; Path=/; HttpOnly
Content-Type: application/json;charset=UTF-8
Content-Length: 43
Date: Fri, 19 Feb 2016 14:17:55 GMT …
Run Code Online (Sandbox Code Playgroud)

cookies android http webview angularjs

5
推荐指数
1
解决办法
1054
查看次数

为什么runOnUiThread()在服务中不起作用?

我正在创建一个应用程序,即使应用程序没有运行,也需要每分钟更新一次值.

当然,我已经设置了一个简单的Service方法.我设置了调试消息,告诉我何时Service启动,何时更新(每分钟)以及何时关闭.我还有一条消息告诉我何时在runOnUiThread()方法内更新值.我的所有消息都被激活,除了那个消息runOnUiThread().有什么我做错了(当然有)?我需要改变什么?

码:

@Override
public void handleMessage(Message message) {

    try {

        if (!serviceStarted) {

            serviceStarted = true;
            serviceTest = true;

            while (serviceStarted) {

                new MainActivity().runOnUiThread(new Runnable() {

                    public void run() {

                            OverviewFragment.refresh(getApplicationContext());
                            System.out.println("yay");

                         }
                });

                Thread.sleep(((1 /* minutes */) * 60 * 1000));
                System.out.println("Updated values through service.");

            }
        }


    } catch (InterruptedException e) {

        Thread.currentThread().interrupt();
        e.printStackTrace();

    }

    stopSelf(message.arg1);
}
Run Code Online (Sandbox Code Playgroud)

android android-service

5
推荐指数
1
解决办法
7611
查看次数

混淆 Android APK 中的资产

我们可以Proguard在 Android Studio 中使用混淆 android APK ,它只会混淆其中的java文件。

问题:我也想混淆存储在 Assets 文件夹中的文件。

解决方案:我们可以使用需要许可证的 Dexguard。

有人可以指出任何免费/开源替代方案吗?

obfuscation android android-studio android-proguard

5
推荐指数
1
解决办法
2418
查看次数