小编par*_*doX的帖子

horizo​​ntalScrollView里面的布局,就是屏幕的大小

我是android新手,一直在寻找解决方案,但到目前为止还没有运气.我想创建一个类似下图的布局.

我想有一个linearLayout,它是屏幕的大小.然后有另一个linearLayout,它也是屏幕的大小,但屏幕外.然后我可以在两个虚拟"屏幕"之间滚动.

在此输入图像描述

有一篇有趣的文章解释了如何扩展scrollView类,以便我可以获得一个很酷的捕捉效果,所以如果我可以让它工作,我的应用程序将感觉很像在主屏幕之间滚动.

我已经阅读了有关权重以及scrollView的fillViewport ="true"的内容.我担心我不明白这些如何与horizo​​ntalScrollView一起使用以使linearLayouts填满屏幕.我尝试过fill_parent和wrap_content的各种组合,但无济于事.

正如我所看到的,只要构建子视图(每个"屏幕"中的元素)并考虑到屏幕可变性,此功能不会损害具有不同屏幕的设备之间的应用程序的可移植性.

这是我尝试的XML的一个简单示例:

<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/HorizontalScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true">

<LinearLayout 
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

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

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/txtTestBox"
            >
        </EditText>
    </LinearLayout>

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

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button 1"
        />

    </LinearLayout>

</LinearLayout>

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

不幸的是,这甚至没有接近我正在寻找的东西.希望这可以做到......

感谢您的任何帮助或建议.

android

11
推荐指数
2
解决办法
6520
查看次数

Android XML定义的维度值产生意外结果

我在我的XML文件中定义了一个dp维度,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="custom_button_Margin">10dp</dimen>
</resources>
Run Code Online (Sandbox Code Playgroud)

我的想法是使用这些值来设置元素之间的填充.当我在布局XML文件中使用该值时,这可以正常工作.

片段:

<RelativeLayout
    android:id="@+id/mainButtons"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="0.4"
    android:layout_margin = "5dp"

    android:gravity="right|bottom">
    <Button
        android:id="@+id/_7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/seven"

        android:background = "@drawable/custom_button"
        android:typeface="monospace"
        android:textSize="@dimen/custom_button_TextSize"

        android:layout_marginRight = "@dimen/custom_button_Margin"
        android:layout_marginBottom = "@dimen/custom_button_Margin"
    />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

问题在于我尝试以编程方式获取此值.我希望得到一个已经缩放以匹配屏幕密度的值.然后我要做的就是按照这里找到的公式(页面很长,看看转换dp单位到像素单位)

我将公式包装在一个函数中,该函数检索文件中定义的值,并将其缩放为像素.

private int get_custom_button_PadV()
    {
    final float scale = getResources().getDisplayMetrics().density;

    return (int) (R.dimen.custom_button_Margin * scale + 0.5f);
    }
Run Code Online (Sandbox Code Playgroud)

当我观察代码时,我看到以下值

scale = 1.0
R.dimen.custom_button_Margin = 2131099650
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么custom_button_Margin值如此之大......我希望它的标度为1.0,那么值为10.我缺少什么?

xml android

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

抑制EditText焦点上的软键盘外观

我试图定义一组按钮,允许用户将数据输入EditText框.我想要EditText框的所有默认功能,除了弹出软键盘.唯一允许进入EditText框的数据应该是我定义的按钮中的数据.我试图通过捕捉触摸事件并返回true来抑制软键盘.(根据此主题发现的对话)

private OnTouchListener txtTouchListener = new OnTouchListener()
    {
    @Override
    public boolean onTouch(View v, MotionEvent event)
        {
        //Return true to suppress the passing of the event on to the OS
        return true;
        }
    };
Run Code Online (Sandbox Code Playgroud)

问题是此方法然后阻止长按事件触发.要解决这个问题,我可以返回false,然后处理长按事件.但是,这会使短按钮弹出软键盘.此外,长时间点击不仅抑制了软键盘,而且上下文菜单也是如此.我正在寻找一种方法来阻止键盘出现短(或长)点击,但保留所有其他功能(短按点击更新光标位置,长按点击显示EditText上下文菜单等)

对此有任何想法非常感谢!

android android-edittext

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

标签 统计

android ×3

android-edittext ×1

xml ×1