页: 1
在扩大<代码>LinearLayout时,我怎么能这样做?
我现在发言:LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 45);
。
页: 1
在扩大<代码>LinearLayout时,我怎么能这样做?
我现在发言:LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 45);
。
The best way to go for this kind of issue is create a dimens.xml
file under values and put in your dip values there, and then in code you pull the dimensions from that file. That s what resources are for, right? =)
以下是<代码>dimens.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="about_image_bottom">0dp</dimen>
</resources>
And this is how you can pull it out in code:
RelativeLayout.LayoutParams iv_params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
iv_params.setMargins(0, 0, 0, (int) getResources().getDimension(R.dimen.about_image_bottom));
之后,你将参数确定到你所需要的任何目标,就我而言,是《图像评论》四:
iv.setLayoutParams(iv_params);
您可使用<条码>斜线/代码>并确定屏幕密度。 与此类似:
int pixelsValue = 5; // margin in pixels
float d = context.getResources().getDisplayMetrics().density;
int margin = (int)(pixelsValue * d);
希望有助于^
Probably the best way would be to specify it in XML. Replace the normal LinearLayout tag with what ever class you created to extend the LinearLayout in the XML tag:
<com.example.MyLinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:orientation="vertical" >
....
See here for more info.
I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...
I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...
I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...
I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...
To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?
When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...
I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...
I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...