小编Hus*_*eky的帖子

在android中设置Button文本字体

我有一个button使用Android小部件创建.我想将按钮文本的字体设置为Helv Neue 67 Med Cond.如何获取此字体并将其设置为android布局文件中的按钮文本?

android android-layout android-fonts android-button

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

MotionEvent中的ACTION_CANCEL和ACTION_UP有什么区别?

我想跟踪屏幕上的手指触摸.所以我所做的就是在MotionEvent触发时开始记录位置ACTION_DOWN,但我怎么知道动作何时结束ACTION_CANCEL,或者ACTION_UP

它们之间的确切区别是什么?

android motion motionevent

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

Android:获取当前的设备方向

我将清单集中的活动方向设为肖像.因为我不希望我的屏幕旋转.

但是在单击按钮时,我想在Android中获取当前的设备方向(纵向或横向)?我不需要从传感器不断更新; 当我点击按钮就足够了当前的设备方向.

PS:设备方向是我拿着我的设备的方式.请勿将其与屏幕方向混合使用.

这是我到目前为止做了什么?

 int PORT=1,LAND=2;

 WindowManager windowService = (WindowManager)getSystemService(Context.WINDOW_SERVICE);

 int rotation = windowService.getDefaultDisplay().getRotation();        

    if (Surface.ROTATION_0 == rotation) {
        rotation = PORT;
    } else if(Surface.ROTATION_180 == rotation) {
        rotation = PORT;
    } else if(Surface.ROTATION_90 == rotation) {
        rotation = LAND;
    } else if(Surface.ROTATION_270 == rotation) {
        rotation = LAND;
    }
 return rotation;
Run Code Online (Sandbox Code Playgroud)

即使使用以下方法也无济于事

getResources().getConfiguration().orientation
Run Code Online (Sandbox Code Playgroud)

它始终返回1,因为我的活动默认设置为纵向.

示例/示例代码将受到高度赞赏.

谢谢.

android screen-orientation device-orientation android-orientation

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

为什么我在Android Studio中收到此错误"原始类型的预期资源"?

我试图通过使用按钮设置默认壁纸,但出于某种原因,当我在OnCreate方法中设置InputStream时,我得到此错误"raw type of raw".我正在引用drawable文件夹并使用drawable文件夹中的icon.png图像.我正在按照NewBoston系列中的教程进行操作,它似乎对Travis工作正常,但由于某种原因,我在Android Studio中无法工作.可能是什么错误?谢谢

Camera.java:

package com.example.user.cameraapplication;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Switch;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by user on 16-08-2015.
 */
public class Camera extends Activity implements View.OnClickListener{

    ImageView iv;
    Button b1,b2;
    ImageButton img;
    Intent i;
    final static  int cameractivity = 0;
    Bitmap b;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photo);
        inititalize();
        InputStream is = getResources().openRawResource(R.drawable.icon);
        b = …
Run Code Online (Sandbox Code Playgroud)

java eclipse android inputstream android-studio

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

FloatingActionButton,layout_anchor和layout_gravity

这里有点新手.我进入Android开发大约两个月,但我在其他环境中有多年的开发经验.

好的.我有一个FloatingActionButton没有出现在我预期或想要的地方.这里面CoordinatorLayout,有一个沿AppBarLayout/ Toolbar和承接ListView.

这是布局:

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout               
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragment_coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ViewVehicleList">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:title="Vehicle List"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

    </android.support.design.widget.AppBarLayout>

    <ListView
        android:id="@+id/Vehicle_ListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:background="#FFFFFF"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </ListView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_AddVehicle"
        style="@style/FloatingAddButton"
        android:src="@drawable/ic_green_add"
        android:layout_gravity="bottom|end"
        app:layout_anchor="@id/Vehicle_ListView"
        android:onClick="addVehicle"/>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

使用此布局,屏幕如下所示: FAB处于错误的位置

layout_gravity"bottom|end".我把它改成了"bottom|right",但我仍然得到了相同的结果.我已经阅读了很多教程,并通过Stack Overflow进行了研究,并且没有运气.

我设法通过删除FAB元素中列出的锚来解决它app:layout_anchor="@id/Vehicle_ListView",这似乎与我读过的内容相反:使用FAB并正确定位它需要使用layout_anchorlayout_gravity.没有锚标记,它看起来像这样:

FAB位置正确

所以这是我的问题:为什么我的锚固定了我的定位FloatingActionButton?我究竟做错了什么?

android android-layout layout-gravity floating-action-button layout-anchor

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

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

在Haskell中创建多态函数

一个简短的搜索并没有帮助我找到答案,所以我开始怀疑它的存在.任务很简单:我想创建一个多态函数,如下所示:

f :: String -> String
f s = show (length s)

f :: Int -> String
f i = show i
Run Code Online (Sandbox Code Playgroud)

为不同类型定义的函数是不同的.有可能,怎么样?

polymorphism haskell function

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

我可以在不使用ScrollView/ListView的情况下使用Pull to Refresh吗?

我试图在我的应用程序中实现Pull to Refresh.

我用android.support.v4.widget.SwipeRefreshLayout包装我的xml代码并且它正常工作,但GUI看起来不太好.

当我向下拉时,我应该看到带有我定义的颜色的常规动画圆圈图标,对吧?但是我认为它是一个空白圆圈,而不是一个带有颜色的转动.

此外,我不能"玩"它甚至在我拉动它之后保持一段时间,它会下降一秒钟(做它做的事情)然后消失.

我认为这是因为我没有使用ListView而是使用LinearLayout.

你怎么看?

码:

XML:

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/swipe">

    <LinearLayout
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:background="#7B68EE"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".HomeActivity">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/loin"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="@string/welcome"
            android:textColor="#B0C4DE"
            android:id="@+id/welcomeBackID"
            android:layout_alignParentTop="true"
            android:layout_alignRight="@+id/webViewCurren"
            android:layout_alignEnd="@+id/webViewCurren" />

        ....

 </android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)

Java的:

public class HomeActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {

    SwipeRefreshLayout mSwipeRefreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe);
        mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_green_light,
                android.R.color.holo_blue_bright,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
        mSwipeRefreshLayout.setOnRefreshListener(this);

    @Override
    public void onRefresh() {
        Toast.makeText(this, "Refresh", Toast.LENGTH_SHORT).show(); …
Run Code Online (Sandbox Code Playgroud)

android listview pull-to-refresh android-studio

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

bash:mongo:找不到命令

我在系统上安装了 mongodb,但是当我使用 Git 进入 bin 目录并输入 mongo 时,就会发生这种情况。

图片

我该怎么办?

mongodb

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

更改按钮内的可绘制尺寸

我想创建一个Button这样的:

按钮示例

这是我的代码:

<Button
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_gravity="center"
    android:drawablePadding="10dp"
    android:id="@+id/button"
    android:text="Play Game"
    android:background="@drawable/ronaldo"
    android:drawableRight="@drawable/messi" />
Run Code Online (Sandbox Code Playgroud)

但是messi.jpeg太大了,并没有在这种情况下显示文字.如何减小图像大小以适应按钮?

愿任何人帮我解决这个问题吗?

android android-image android-layout android-button android-drawable

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