我需要做一个非常简单的事情 - 找出是否显示了软件键盘.这在Android中可行吗?
我正在使用TableLayout.我需要为此布局同时进行水平和垂直滚动.默认情况下,我可以在视图中进行垂直滚动,但水平滚动不起作用.
我使用的是Android SDK 1.5 r3.我已经尝试过了android:scrollbars="horizontal".
我在一些论坛上看到,在杯形蛋糕更新中,水平滚动是可能的.
如何让我的布局在两个方向上滚动?
我正在构建一个我需要处理触摸事件的界面.特别是我能够将它们仅启用到片段中的受限区域.为了更好地理解问题,尊重标准和我的应用程序的目标,我计划了导航抽屉,它假设存在许多片段(而不是活动).触摸事件的活动很容易实现,另一方面,我在互联网上读到,片段可能会成为一个问题.
我的应用程序在体系结构级别如下: - MainActivity.java - NavigationDrawer.java - TestFragment.java(现在单个片段,等待解决问题)
我没有找到解释如何做得好(或如何解决问题)的解决方案或教程.然后我问你,简化问题只是" 在片段中启用触摸事件(在这种情况下为getPressure()) ".下面是一些可能有助于解决问题的代码:
TestFragment
public class TestFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public static TestFragment newInstance(int sectionNumber) {
TestFragment fragment = new TestFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public TestFragment() {}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_test, container, false);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PdfRenderer,并且要求使用Zoom和scroll可用,但在Android PdfRenderer中不提供任何缩放和滚动支持,只有页面导航支持可用.
但我猜缩放和滚动支持可以实现,因为PdfRenderer使用位图来使用imageview显示内容.
如何使用Google PdfRenderer示例实现缩放和滚动支持?
PS:我正在使用Google提供的这个PdfRenderer示例,https://github.com/googlesamples/android-PdfRendererBasic
我在为Android编程时非常新.我的应用程序是来自开发者android网站上的api demos的示例应用程序.当我更改该样本绘图中的参数时,它会变大.该绘图需要在滚动视图中显示(不需要缩小以适应屏幕).这是我使用的代码:
DrawPoints.java
public class DrawPoints extends myActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.routes);
}
public static class SampleView extends View {
private Paint mPaint = new Paint();
private float[] mPts;
/*here comes declaration of parametars
private void buildPoints() {
/*here comes some coding*/
}
}
public SampleView(Context context, AttributeSet attributeset) {
super(context, attributeSet);
buildPoints();
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = mPaint;
//here also comes code
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是xml代码:
routes.xml
<?xml version="1.0" …Run Code Online (Sandbox Code Playgroud) 我在ViewFlipper中有一个垂直的ScrollView(实际上是一个自定义的ScrollView,代码如下).除非我在ScrollView上水平滑动以翻转到上一个/下一个视图,否则ViewFlipper工作正常.ScrollView本身可以正常工作.
这是设计.绿色框是ScrollView,它应该是垂直的.

这是ScrollView:
public class SCScrollView extends ScrollView {
private float xDistance, yDistance, lastX, lastY;
GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector());
OnTouchListener gestureListener;
public SCScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
gestureListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
lastX = ev.getX();
lastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE: …Run Code Online (Sandbox Code Playgroud) 我在水平滚动视图中实现了一个表格布局,它也是垂直滚动视图的子级。它是这样工作的;当垂直或水平滚动时,它为每种滚动类型明确滚动。意味着垂直滚动时水平滚动根本不会发生,比如说如果手指对角移动,则不会发生垂直或水平滚动。要水平滚动它,必须再次触摸它并且它仅在水平方向滚动,如果手指对角移动,则不会发生垂直或水平滚动。[此处相同]。
似乎在一个手指触摸实例中只处理一个回调。我也需要对角滚动,应该同时垂直和水平滚动,就像在 iOS 表视图中一样。向所有 6 个方向滚动。
这是代码;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ScrollView
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dip"
android:scrollbars="none">
<HorizontalScrollView
android:id="@+id/horizontalView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:scrollbars="horizontal|vertical">
<TableLayout
android:id="@+id/tlGridTable"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:id="@+id/row1"
android:layout_width="wrap_content"
android:layout_height="50dp">
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_margin="4dp"
android:background="@android:color/holo_green_light"/>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_margin="4dp"
android:background="@android:color/holo_green_light"/>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_margin="4dp"
android:background="@android:color/holo_green_light"/>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_margin="4dp"
android:background="@android:color/holo_green_light"/>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_margin="4dp"
android:background="@android:color/holo_green_light"/>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_margin="4dp"
android:background="@android:color/holo_green_light"/>
<ImageView
android:layout_width="100dp"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"
android:layout_margin="4dp"
android:background="@android:color/holo_green_light"/>
</TableRow>
<TableRow
android:id="@+id/row1" …Run Code Online (Sandbox Code Playgroud) 我想制作一个UI像a 的元素GridView,我希望它是完整的功能,但希望它可以水平滚动而不是垂直.
通过水平滚动我的意思是它应该以这种方式构建而不是放入HorizontalScrollView.
我Custom GridView将会有固定数量的rows发言权4-5,而且columns应该extensible基于该项目的数量Adapter.您可以将其视为本机GridView所做的相反,但它应该保持功能.
我已经查看GridView了Google 如何实现的源代码,但是我能够理解得非常少,并且开始View从头开始并不是一个好主意,因为我担心我将无法按照谷歌的方式做事记忆优化.
我观察到GridView扩展AbsListView,所以我的问题是,它AbsListView是允许GridView垂直滚动并从适配器添加项目,还是GridView添加垂直滚动功能?我应该调整GridView还是AbsListView?
知道是否已经做了我想做的事情会更好吗?
这已在Android Honeycomb 3.1及更高版本的原生图库和YouTube应用中实施.所以,如果有人有想法,请详细说明.
Honeycomb Gallery应用程序的快照:

Honeycomb YouTube应用程序的快照:

android android-custom-view android-listview android-gridview android-view
我已经将图像设置为linearlayout的背景。这是代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mainbg"
android:orientation="vertical"
android:padding="5dp"
>
Run Code Online (Sandbox Code Playgroud)
问题是,图像的宽度约为2000像素,我不想缩小与屏幕的比例,我只想显示与背景一样多的东西,而不是拉长它。
我该怎么办?
谢谢
我想创建一个动态扩展的布局,可以反映到用户的输入.首先,我创建了一个允许向两个方向滚动的活动布局(这不是我的发明,我使用了评论中解释的另一个问题并进行了一些改进):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="false"
android:clipToPadding="false"
tools:ignore="UselessParent" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="false"
android:clipToPadding="false" >
<RelativeLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="false"
android:clipToPadding="false" >
</RelativeLayout>
</FrameLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
然后,我在下面创建了一个简单的UI布局,一个文本视图和一个垂直线性布局.这是我的message_with_replies.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/header"
android:layout_width="300dp"
android:layout_height="wrap_content" >
<!-- some text views and buttons here,
I've removed them to keep things simple,
see the screenshot below -->
</LinearLayout>
<LinearLayout
android:id="@+id/replies"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
请注意 …
android ×11
scrollview ×2
android-view ×1
drawing2d ×1
java ×1
pdfrenderer ×1
touch-event ×1
visibility ×1